|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yiisoft\Yii\Middleware; |
|
6
|
|
|
|
|
7
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
8
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
|
9
|
|
|
use Psr\Http\Server\MiddlewareInterface; |
|
10
|
|
|
use Psr\Http\Server\RequestHandlerInterface; |
|
11
|
|
|
use Yiisoft\ErrorHandler\HeadersProvider; |
|
|
|
|
|
|
12
|
|
|
use Yiisoft\Http\Header; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Adds Cross-Origin Resource Sharing (CORS) headers allowing everything to the response. |
|
16
|
|
|
*/ |
|
17
|
|
|
final class CorsAllowAll implements MiddlewareInterface |
|
18
|
1 |
|
{ |
|
19
|
|
|
public function __construct( |
|
20
|
1 |
|
private HeadersProvider $headersProvider |
|
21
|
|
|
) { |
|
22
|
1 |
|
} |
|
23
|
1 |
|
|
|
24
|
1 |
|
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
|
25
|
1 |
|
{ |
|
26
|
1 |
|
$this->headersProvider->add(Header::ACCESS_CONTROL_ALLOW_ORIGIN, '*'); |
|
27
|
1 |
|
$this->headersProvider->add(Header::ACCESS_CONTROL_ALLOW_METHODS, 'GET,OPTIONS,HEAD,POST,PUT,PATCH,DELETE'); |
|
28
|
1 |
|
$this->headersProvider->add(Header::ACCESS_CONTROL_ALLOW_HEADERS, '*'); |
|
29
|
1 |
|
$this->headersProvider->add(Header::ACCESS_CONTROL_EXPOSE_HEADERS, '*'); |
|
30
|
1 |
|
$this->headersProvider->add(Header::ACCESS_CONTROL_ALLOW_CREDENTIALS, 'true'); |
|
31
|
|
|
$this->headersProvider->add(Header::ACCESS_CONTROL_MAX_AGE, '86400'); |
|
32
|
|
|
|
|
33
|
|
|
$response = $handler->handle($request); |
|
34
|
|
|
|
|
35
|
|
|
return $response |
|
36
|
|
|
->withHeader(Header::ALLOW, '*') |
|
37
|
|
|
->withHeader(Header::VARY, 'Origin') |
|
38
|
|
|
->withHeader(Header::ACCESS_CONTROL_ALLOW_ORIGIN, '*') |
|
39
|
|
|
->withHeader(Header::ACCESS_CONTROL_ALLOW_METHODS, 'GET,OPTIONS,HEAD,POST,PUT,PATCH,DELETE') |
|
40
|
|
|
->withHeader(Header::ACCESS_CONTROL_ALLOW_HEADERS, '*') |
|
41
|
|
|
->withHeader(Header::ACCESS_CONTROL_EXPOSE_HEADERS, '*') |
|
42
|
|
|
->withHeader(Header::ACCESS_CONTROL_ALLOW_CREDENTIALS, 'true') |
|
43
|
|
|
->withHeader(Header::ACCESS_CONTROL_MAX_AGE, '86400'); |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths