定制 mehmetik/cors 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mehmetik/cors

最新稳定版本:1.0

Composer 安装命令:

composer require mehmetik/cors

包简介

The `CorsSupport` class is a library for managing cross-origin resource sharing (CORS) and a middleware that operates on HTTP requests and responses in a stack application.

关键字:

README 文档

README

This package provides a library and stack middleware for handling Cross-Origin Resource Sharing (CORS) in a Stack application.

Installation

To install the package, require it through Composer.

composer require mehmetik/cors

Usage

This package can be used as a library or as stack middleware.

Options

Option Description Type Default value
allowedMethods Matches the request method. string[] []
allowedOrigins Matches the request origin. string[] []
allowedOriginsPatterns Matches the request origin with preg_match. string[] []
allowedHeaders Sets the Access-Control-Allow-Headers response header. string[] []
exposedHeaders Sets the Access-Control-Expose-Headers response header. string[] []
maxAge Sets the Access-Control-Max-Age response header. int false
supportsCredentials Sets the Access-Control-Allow-Credentials header. bool false

The allowedMethods and allowedHeaders options are case-insensitive.

You don't need to provide both allowedOrigins and allowedOriginsPatterns. If one of the strings passed matches, it is considered a valid origin.

If ['*'] is provided to allowedMethods, allowedOrigins or allowedHeaders all methods / origins / headers are allowed.

Example: using the library

<?php
use mehmetik\Cors\CorsSupport;

$cors = new CorsSupport([
    'allowedHeaders'         => ['x-allowed-header', 'x-other-allowed-header'],
    'allowedMethods'         => ['DELETE', 'GET', 'POST', 'PUT'],
    'allowedOrigins'         => ['http://localhost'],
    'allowedOriginsPatterns' => ['/localhost:\d/'],
    'exposedHeaders'         => false,
    'maxAge'                 => false,
    'supportsCredentials'    => false,
]);

$cors->addActualRequestHeaders(Response $response, $origin);
$cors->handlePreflightRequest(Request $request);
$cors->isActualRequestAllowed(Request $request);
$cors->isCorsRequest(Request $request);
$cors->isPreflightRequest(Request $request);

Example: using the stack middleware

<?php
use mehmetik\Cors\Cors;

$app = new Stack\Builder();
$app->push(new Cors($app, [
    'allowedHeaders'         => ['x-allowed-header', 'x-other-allowed-header'],
    'allowedMethods'         => ['DELETE', 'GET', 'POST', 'PUT'],
    'allowedOrigins'         => ['http://localhost'],
    'allowedOriginsPatterns' => ['/localhost:\d/'],
    'exposedHeaders'         => false,
    'maxAge'                 => false,
    'supportsCredentials'    => false,
]));

License

This package is licensed under the MIT License. See the LICENSE file for details.

统计信息

  • 总下载量: 6
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-12-27

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固