1 | <?php |
||
8 | trait ManipulateHttpResponse |
||
9 | { |
||
10 | /** |
||
11 | * HTTP Request object. |
||
12 | * |
||
13 | * @var \Symfony\Component\HttpFoundation\HeaderBag |
||
14 | */ |
||
15 | protected $requestHeaders; |
||
16 | |||
17 | /** |
||
18 | * Acknowledge the ESI support and send a specific |
||
19 | * HTTP header as a reply. |
||
20 | * |
||
21 | * @param \Illuminate\Http\Response $response |
||
22 | * |
||
23 | * @return void |
||
24 | */ |
||
25 | protected function acknowledgeEsiSupport(Response $response) |
||
33 | |||
34 | /** |
||
35 | * Add cacheable header so varnish can recognize |
||
36 | * the response as a cacheable content. |
||
37 | * |
||
38 | * @param \Illuminate\Http\Response $response |
||
39 | * @param int $cacheDuration |
||
40 | */ |
||
41 | protected function addCacheableHeader(Response $response, $cacheDuration) |
||
48 | |||
49 | /** |
||
50 | * Add uncacheable header so varnish can recognize |
||
51 | * the response as an uncacheable content. |
||
52 | * |
||
53 | * @param \Illuminate\Http\Response $response |
||
54 | */ |
||
55 | public function addUncacheableHeader(Response $response) |
||
59 | |||
60 | /** |
||
61 | * Add an ETag header to the current response. |
||
62 | * |
||
63 | * @param \Illuminate\Http\Response $response |
||
64 | * |
||
65 | * @return void |
||
66 | */ |
||
67 | protected function addEtagHeader(Response $response) |
||
73 | |||
74 | /** |
||
75 | * Normalize the given cache duration and convert |
||
76 | * it to seconds. |
||
77 | * |
||
78 | * @param int $duration |
||
79 | * |
||
80 | * @return int|float |
||
81 | */ |
||
82 | protected function getCacheDuration($duration) |
||
88 | |||
89 | /** |
||
90 | * Manipulate the current Http response. |
||
91 | * |
||
92 | * @param \Illuminate\Http\Response $response |
||
93 | * @param int $cacheDuration |
||
94 | * |
||
95 | * @return \Illuminate\Http\Response |
||
96 | */ |
||
97 | public function manipulate(Response $response, $cacheDuration) |
||
110 | |||
111 | /** |
||
112 | * Set the current Http request headers. |
||
113 | * |
||
114 | * @param \Symfony\Component\HttpFoundation\HeaderBag $headers |
||
115 | */ |
||
116 | public function setRequestHeaders(HeaderBag $headers) |
||
120 | |||
121 | /** |
||
122 | * Check if the current response shouldn't be cached. |
||
123 | * |
||
124 | * @param \Illuminate\Http\Response $response |
||
125 | * |
||
126 | * @return string|array |
||
127 | */ |
||
128 | protected function shouldNotCache(Response $response) |
||
132 | |||
133 | /** |
||
134 | * Get configuration value for a specific key. |
||
135 | * |
||
136 | * @param string $key |
||
137 | * |
||
138 | * @return mixed |
||
139 | */ |
||
140 | abstract public function getConfig($key); |
||
141 | } |
||
142 |