Passed
Push — master ( e9d49a...8cc129 )
by Alexander
03:00
created

AllowAllCors::process()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

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 10
cts 10
cp 1
crap 1
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 1
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
19
    {
20 1
        $response = $handler->handle($request);
21
22 1
        return $response
23 1
            ->withHeader(Header::ALLOW, '*')
24 1
            ->withHeader(Header::VARY, 'Origin')
25 1
            ->withHeader(Header::ACCESS_CONTROL_ALLOW_ORIGIN, '*')
26 1
            ->withHeader(Header::ACCESS_CONTROL_ALLOW_METHODS, 'GET,OPTIONS,HEAD,POST,PUT,PATCH,DELETE')
27 1
            ->withHeader(Header::ACCESS_CONTROL_ALLOW_HEADERS, '*')
28 1
            ->withHeader(Header::ACCESS_CONTROL_ALLOW_CREDENTIALS, 'true')
29 1
            ->withHeader(Header::ACCESS_CONTROL_MAX_AGE, '86400');
30
    }
31
}
32