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
|
|
|
|