protected function UrlRegistrar::determine in URLs queuer 8
Determine what to do with the given response object.
Parameters
\Symfony\Component\HttpFoundation\Request $request: A Request object.
\Symfony\Component\HttpFoundation\Response $response: A Response object.
Return value
true|false|null
- NULL: Ignore the response, delete it from the registry if it exists.
- FALSE: Ignore the response, do not add to traffic registry.
- TRUE: Add the response to the traffic registry.
1 call to UrlRegistrar::determine()
- UrlRegistrar::handle in src/
StackMiddleware/ UrlRegistrar.php
File
- src/
StackMiddleware/ UrlRegistrar.php, line 98
Class
- UrlRegistrar
- Collects URLs for all passing traffic.
Namespace
Drupal\purge_queuer_url\StackMiddlewareCode
protected function determine(Request $request, Response $response) {
if (!$response instanceof CacheableResponseInterface) {
return FALSE;
}
// When page_cache is enabled, skip HITs to prevent running code twice.
if ($cached = $response->headers
->get('X-Drupal-Cache')) {
if ($cached === 'HIT') {
return FALSE;
}
}
// Don't gather responses that aren't going to be useful.
if (!count($response
->getCacheableMetadata()
->getCacheTags())) {
return NULL;
}
// Don't gather responses with dynamic elements in them.
if ($response
->getMaxAge() < 1) {
return NULL;
}
// Only allow ordinary responses, so prevent collecting 403's and redirects.
if ($response
->getStatusCode() !== 200) {
return NULL;
}
// Check if there are blacklisted patterns in the URL.
$url = $this
->generateUrlOrPathToRegister($request);
if (is_array($this->blacklist)) {
foreach ($this->blacklist as $needle) {
if (strpos($url, $needle) !== FALSE) {
return NULL;
}
}
}
return TRUE;
}