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

AllowAllCors   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 14
ccs 0
cts 10
cp 0
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 12 1
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