DebugMiddleware::pragmaHeaders()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 1
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * This file is part of the RHDC Akamai middleware package.
4
 *
5
 * (c) Shawn Iwinski <[email protected]>
6
 *
7
 * For the full copyright and license information, please view
8
 * the LICENSE file that was distributed with this source code.
9
 */
10
namespace Rhdc\Akamai\Middleware\Request;
11
12
use Psr\Http\Message\RequestInterface;
13
14
/**
15
 * @see https://community.akamai.com/community/web-performance/blog/2015/03/31/using-akamai-pragma-headers-to-investigate-or-troubleshoot-akamai-content-delivery
16
 */
17
class DebugMiddleware implements MiddlewareInterface
18
{
19
    /**
20
     * Akamai debug pragma header values
21
     *
22
     * @var string[]
23
     */
24
    protected static $pragmaHeaders = array(
25
        'akamai-x-cache-on',
26
        'akamai-x-cache-remote-on',
27
        'akamai-x-check-cacheable',
28
        'akamai-x-feo-trace',
29
        'akamai-x-get-cache-key',
30
        'akamai-x-get-client-ip',
31
        'akamai-x-get-extracted-values',
32
        'akamai-x-get-nonces',
33
        'akamai-x-get-request-id',
34
        'akamai-x-get-ssl-client-session-id',
35
        'akamai-x-get-true-cache-key',
36
        'akamai-x-serial-no',
37
    );
38
39
    /**
40
     * Returns array of Akamai debug pragma header values
41
     *
42
     * @return string[]
43
     */
44 2
    public static function pragmaHeaders()
45
    {
46 2
        return static::$pragmaHeaders;
47
    }
48
49
    /**
50
     * Returns a new modified request instance with Akamai debug pragma headers
51
     *
52
     * - If the original request does not already have a pragma header, it will
53
     *   be added with the Akamai debug values
54
     * - If the original request already has a pragma header, the Akamai debug
55
     *   values will be combined with the existing value(s)
56
     *
57
     * @param RequestInterface $request Original request
58
     *
59
     * @return RequestInterface New modified request instance with Akamai debug pragma headers
60
     */
61 2
    public function __invoke(RequestInterface $request)
62
    {
63 2
        return $request->withAddedHeader('Pragma', static::$pragmaHeaders);
64
    }
65
}
66