Skip to content

Commit 005d609

Browse files
author
Till Hildebrandt
committed
Fixing Pull Request Requests
- outsourced checking of blacklisted_paths to new method "isCacheableRequest" - removed related functionality from "isCacheable" - removed obsolete comment
1 parent a9e1d11 commit 005d609

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Change Log
22

3-
## 1.6.1 - 2019-11-25
3+
## 1.7.0 - unreleased
44

55
### Added
66

src/CachePlugin.php

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ protected function doHandleRequest(RequestInterface $request, callable $next, ca
181181
return $this->handleCacheListeners($request, $this->createResponseFromCacheItem($cacheItem), true, $cacheItem);
182182
}
183183

184-
if ($this->isCacheable($request, $response)) {
184+
if ($this->isCacheable($response) && $this->isCacheableRequest($request)) {
185185
$bodyStream = $response->getBody();
186186
$body = $bodyStream->__toString();
187187
if ($bodyStream->isSeekable()) {
@@ -244,26 +244,37 @@ private function calculateResponseExpiresAt($maxAge)
244244
/**
245245
* Verify that we can cache this response.
246246
*
247-
* @param RequestInterface $request
248247
* @param ResponseInterface $response
249248
*
250249
* @return bool
251250
*/
252-
protected function isCacheable(RequestInterface $request, ResponseInterface $response)
251+
protected function isCacheable(ResponseInterface $response)
253252
{
254253
if (!in_array($response->getStatusCode(), [200, 203, 300, 301, 302, 404, 410])) {
255254
return false;
256255
}
257256

258-
foreach ($this->config['blacklisted_paths'] as $not_to_cache_path) {
259-
if (1 === preg_match('/'.$not_to_cache_path.'/', $request->getRequestTarget())) {
257+
$nocacheDirectives = array_intersect($this->config['respect_response_cache_directives'], $this->noCacheFlags);
258+
foreach ($nocacheDirectives as $nocacheDirective) {
259+
if ($this->getCacheControlDirective($response, $nocacheDirective)) {
260260
return false;
261261
}
262262
}
263263

264-
$nocacheDirectives = array_intersect($this->config['respect_response_cache_directives'], $this->noCacheFlags);
265-
foreach ($nocacheDirectives as $nocacheDirective) {
266-
if ($this->getCacheControlDirective($response, $nocacheDirective)) {
264+
return true;
265+
}
266+
267+
/**
268+
* Verify that we can cache this request.
269+
*
270+
* @param RequestInterface $request
271+
*
272+
* @return bool
273+
*/
274+
protected function isCacheableRequest(RequestInterface $request)
275+
{
276+
foreach ($this->config['blacklisted_paths'] as $not_to_cache_path) {
277+
if (1 === preg_match('/'.$not_to_cache_path.'/', $request->getRequestTarget())) {
267278
return false;
268279
}
269280
}
@@ -358,7 +369,7 @@ private function configureOptions(OptionsResolver $resolver)
358369
'respect_response_cache_directives' => ['no-cache', 'private', 'max-age', 'no-store'],
359370
'cache_key_generator' => null,
360371
'cache_listeners' => [],
361-
'blacklisted_paths' => [], // restricted for
372+
'blacklisted_paths' => [],
362373
]);
363374

364375
$resolver->setAllowedTypes('cache_lifetime', ['int', 'null']);

0 commit comments

Comments
 (0)