Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laravel 8 support #29

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This package adds [Cross-Origin Resource Sharing](http://www.w3.org/TR/cors/) (C

The package is based on [Framework agnostic (PSR-7) CORS implementation](https://github.com/neomerx/cors-psr7).

The **current version V3** is designed for Laravel 6 or higher. If you use lower Laravel version please use **V2**.
The **current version V4** is designed for Laravel 8 or higher. If you use lower Laravel version please use **V2**.

## Install

Expand Down Expand Up @@ -106,7 +106,7 @@ As Lumen does not support `vendor:publish` command file `vendor/neomerx/cors-ill

## Exceptions and CORS headers

When exceptions are thrown and responses are created in [Laravel/Lumen exception handlers](https://laravel.com/docs/6.x/errors) middleware will be excluded from handling responses. It means CORS middleware will not add its CORS headers to responses. For this reason CORS results (including headers) are registered in [Laravel/Lumen Container](https://laravel.com/docs/6.x/container) and made accessible from any part of your application including exception handlers.
When exceptions are thrown and responses are created in [Laravel/Lumen exception handlers](https://laravel.com/docs/8.x/errors) middleware will be excluded from handling responses. It means CORS middleware will not add its CORS headers to responses. For this reason CORS results (including headers) are registered in [Laravel/Lumen Container](https://laravel.com/docs/8.x/container) and made accessible from any part of your application including exception handlers.

Code sample for reading CORS headers

Expand All @@ -132,11 +132,11 @@ The following methods of class `CorsMiddleware` could be replaced in descendant

Additionally a custom [AnalysisStrategyInterface](https://github.com/neomerx/cors-psr7/blob/master/src/Contracts/AnalysisStrategyInterface.php) could be injected by
- overriding `getCreateAnalysisStrategyClosure` method in `ServiceProvider` for Laravel/Lumen
- using [Laravel/Lumen Container binding](https://laravel.com/docs/6.x/container) for interface `AnalysisStrategyInterface`
- using [Laravel/Lumen Container binding](https://laravel.com/docs/8.x/container) for interface `AnalysisStrategyInterface`

Also custom [AnalyzerInterface](https://github.com/neomerx/cors-psr7/blob/master/src/Contracts/AnalyzerInterface.php) could be injected by
- overriding `getCreateAnalyzerClosure` method in `ServiceProvider` for Laravel/Lumen
- using [Laravel/Lumen Container binding](https://laravel.com/docs/6.x/container) for interface `AnalyzerInterface`
- using [Laravel/Lumen Container binding](https://laravel.com/docs/8.x/container) for interface `AnalyzerInterface`

## Testing

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
}
],
"require": {
"php": ">=7.2.0",
"php": ">=7.3.0",
"psr/http-message": "^1.0",
"psr/log": "^1.0",
"illuminate/http": "^6.0",
"illuminate/http": "^8.0",
"neomerx/cors-psr7": "^2.0"
},
"require-dev": {
Expand Down
2 changes: 1 addition & 1 deletion src/Adapters/IlluminateRequestToPsr7.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function hasHeader($name)
*/
public function getHeader($name)
{
return $this->request->headers->get($name, null, false);
return $this->request->headers->all($name);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/CorsMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public function testActualCors(): void
/** @var Response $response */
$this->assertNotNull($response = $this->middleware->handle($this->request, $next));
$this->assertTrue($nextCalled);
$this->assertEquals(['value 1', 'value 2'], $response->headers->get($headerName, null, false));
$this->assertEquals(['value 1', 'value 2'], $response->headers->all($headerName));
$this->assertEquals('expose1, expose2', $response->headers->get(CorsResponseHeaders::EXPOSE_HEADERS));
}

Expand Down