项目作者: labrador-kennel

项目描述 :
Middleware for @amphp http-server to handle CORS requests!
高级语言: PHP
项目地址: git://github.com/labrador-kennel/http-cors.git
创建时间: 2019-02-09T06:40:19Z
项目社区:https://github.com/labrador-kennel/http-cors

开源协议:MIT License

下载


Labrador HTTP CORS

GitHub release
GitHub license

A PHP 8+ library intended to provide spec-compliant CORS middleware for projects running on Amp’s http-server.
Though this library lives under the Labrador namespace it has only one dependency, amphp/http-server, and does not depend
on any other Labrador packages.

Installation

Composer is the only supported method for installing Labrador packages.

  1. composer require cspray/labrador-http-cors

Example

Below is an example using the fluent API. Please check out the documentation for more details and examples of non-fluent
usage.

  1. <?php
  2. use Cspray\Labrador\Http\Cors\ConfigurationBuilder;
  3. use Cspray\Labrador\Http\Cors\SimpleConfigurationLoader;
  4. use Cspray\Labrador\Http\Cors\CorsMiddleware;
  5. $configuration = ConfigurationBuilder::forOrigins('https://example.com', 'https://foo.example.com')
  6. ->allowMethods('GET', 'POST', 'PUT', 'DELETE')
  7. ->withMaxAge(8600)
  8. ->allowRequestHeaders('X-Request-Header')
  9. ->exposeResponseHeaders('X-Response-Header')
  10. ->doAllowCredentials()
  11. ->build();
  12. $loader = new SimpleConfigurationLoader($configuration);
  13. $middleware = new CorsMiddleware($loader);

Supported Versions

Only the 1.x release series is officially supported at this time. The previous 0.x release series will not see new
features and will only see critical security fixes.

Documentation

Labrador packages have thorough documentation in-repo in the docs/ directory. You can also check out the documentation
online at https://labrador-kennel.io/docs/http-cors.

Governance

All Labrador packages adhere to the rules laid out in the Labrador Governance repo.