Passed
Push — master ( ed917d...0cc967 )
by Alexander
15:07 queued 12:17
created

AllowAllCors::process()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 12
ccs 0
cts 10
cp 0
crap 2
rs 9.9666
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\Http\Header;
12
13
/**
14
 * `AllowAllCors` adds CORS headers to the response.
15
 */
16
final class AllowAllCors implements MiddlewareInterface
17
{
18
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
19
    {
20
        $response = $handler->handle($request);
21
22
        return $response
23
            ->withHeader(Header::ALLOW, '*')
24
            ->withHeader(Header::VARY, 'Origin')
25
            ->withHeader(Header::ACCESS_CONTROL_ALLOW_ORIGIN, '*')
26
            ->withHeader(Header::ACCESS_CONTROL_ALLOW_METHODS, 'GET,OPTIONS,HEAD,POST,PUT,PATCH,DELETE')
27
            ->withHeader(Header::ACCESS_CONTROL_ALLOW_HEADERS, '*')
28
            ->withHeader(Header::ACCESS_CONTROL_ALLOW_CREDENTIALS, 'true')
29
            ->withHeader(Header::ACCESS_CONTROL_MAX_AGE, '86400');
30
    }
31
}
32