@@ -192,26 +192,26 @@ public function __invoke(RequestInterface $request, ResponseInterface $response,
192
192
$ response = $ next ($ request , $ response );
193
193
194
194
if (!$ this ->isResponseStatusValid ($ response )) {
195
- return $ response -> withHeader ( ' Cache-Control ' , ' no-cache, no-store, must-revalidate ' );
195
+ return $ this -> noCacheResponse ( $ response );
196
196
}
197
197
198
198
if (!$ this ->isPathIncluded ($ path )) {
199
- return $ response -> withHeader ( ' Cache-Control ' , ' no-cache, no-store, must-revalidate ' );
199
+ return $ this -> noCacheResponse ( $ response );
200
200
}
201
201
202
202
if ($ this ->isPathExcluded ($ path )) {
203
- return $ response -> withHeader ( ' Cache-Control ' , ' no-cache, no-store, must-revalidate ' );
203
+ return $ this -> noCacheResponse ( $ response );
204
204
}
205
205
206
206
if (!$ this ->isQueryIncluded ($ query )) {
207
207
$ queryArr = $ this ->parseIgnoredParams ($ query );
208
208
if (!empty ($ queryArr )) {
209
- return $ response -> withHeader ( ' Cache-Control ' , ' no-cache, no-store, must-revalidate ' );
209
+ return $ this -> noCacheResponse ( $ response );
210
210
}
211
211
}
212
212
213
213
if ($ this ->isQueryExcluded ($ query )) {
214
- return $ response -> withHeader ( ' Cache-Control ' , ' no-cache, no-store, must-revalidate ' );
214
+ return $ this -> noCacheResponse ( $ response );
215
215
}
216
216
217
217
// Nothing has excluded the cache so far: add it to the pool.
@@ -401,4 +401,22 @@ private function parseIgnoredParams(array $queryParams)
401
401
402
402
return array_diff_key ($ queryParams , array_flip ((array )$ this ->ignoredQuery ));
403
403
}
404
+
405
+ /**
406
+ * Disable the HTTP cache headers
407
+ *
408
+ * - Cache-Control is the proper HTTP
409
+ * - Pragma is for HTTP 1.0 support
410
+ * - Expires is an alternative that also is supported by 1.0 proxies
411
+ *
412
+ * @param ResponseInterface $response
413
+ * @return ResponseInterface
414
+ */
415
+ private function noCacheResponse (ResponseInterface $ response )
416
+ {
417
+ return $ response
418
+ ->withHeader ('Cache-Control ' , 'no-cache, no-store, must-revalidate ' )
419
+ ->withHeader ('Pragma ' , 'no-cache ' )
420
+ ->withHeader ('Expires ' , '0 ' );
421
+ }
404
422
}
0 commit comments