PHPackages                             mehmetik/cors - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. mehmetik/cors

ActiveLibrary[HTTP &amp; Networking](/categories/http)

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.

1.0(3y ago)26MITPHPPHP ^7.2|^8.0

Since Dec 27Pushed 3y ago1 watchersCompare

[ Source](https://github.com/mehmetik/cors)[ Packagist](https://packagist.org/packages/mehmetik/cors)[ Docs](https://github.com/mehmetik/cors)[ RSS](/packages/mehmetik-cors/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (4)Versions (2)Used By (0)

mehmetik/cors
=============

[](#mehmetikcors)

This package provides a library and stack middleware for handling Cross-Origin Resource Sharing (CORS) in a [Stack](https://github.com/stackphp/stack) application.

Installation
------------

[](#installation)

To install the package, require it through Composer.

```
composer require mehmetik/cors
```

Usage
-----

[](#usage)

This package can be used as a library or as [stack middleware](http://stackphp.com/).

### Options

[](#options)

OptionDescriptionTypeDefault valueallowedMethodsMatches the request method.`string[]``[]`allowedOriginsMatches the request origin.`string[]``[]`allowedOriginsPatternsMatches the request origin with `preg_match`.`string[]``[]`allowedHeadersSets the Access-Control-Allow-Headers response header.`string[]``[]`exposedHeadersSets the Access-Control-Expose-Headers response header.`string[]``[]`maxAgeSets the Access-Control-Max-Age response header.`int``false`supportsCredentialsSets 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

[](#example-using-the-library)

```
