summaryrefslogtreecommitdiffstats
path: root/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php
diff options
context:
space:
mode:
Diffstat (limited to 'core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php')
-rw-r--r--core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php27
1 files changed, 22 insertions, 5 deletions
diff --git a/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php
index 4007003..f7d513b 100644
--- a/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php
+++ b/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php
@@ -115,13 +115,30 @@ class FinishResponseSubscriber implements EventSubscriberInterface {
$response->headers->set('X-Content-Type-Options', 'nosniff', FALSE);
$response->headers->set('X-Frame-Options', 'SAMEORIGIN', FALSE);
+ // If the current response isn't an implementation of the
+ // CacheableResponseInterface, we assume that a Response is either
+ // explicitly not cacheable or that caching headers are already set in
+ // another place.
+ if (!$response instanceof CacheableResponseInterface) {
+ if (!$this->isCacheControlCustomized($response)) {
+ $this->setResponseNotCacheable($response, $request);
+ }
+
+ // HTTP/1.0 proxies do not support the Vary header, so prevent any caching
+ // by sending an Expires date in the past. HTTP/1.1 clients ignore the
+ // Expires header if a Cache-Control: max-age directive is specified (see
+ // RFC 2616, section 14.9.3).
+ if (!$response->headers->has('Expires')) {
+ $this->setExpiresNoCache($response);
+ }
+ return;
+ }
+
// Expose the cache contexts and cache tags associated with this page in a
// X-Drupal-Cache-Contexts and X-Drupal-Cache-Tags header respectively.
- if ($response instanceof CacheableResponseInterface) {
- $response_cacheability = $response->getCacheableMetadata();
- $response->headers->set('X-Drupal-Cache-Tags', implode(' ', $response_cacheability->getCacheTags()));
- $response->headers->set('X-Drupal-Cache-Contexts', implode(' ', $this->cacheContextsManager->optimizeTokens($response_cacheability->getCacheContexts())));
- }
+ $response_cacheability = $response->getCacheableMetadata();
+ $response->headers->set('X-Drupal-Cache-Tags', implode(' ', $response_cacheability->getCacheTags()));
+ $response->headers->set('X-Drupal-Cache-Contexts', implode(' ', $this->cacheContextsManager->optimizeTokens($response_cacheability->getCacheContexts())));
$is_cacheable = ($this->requestPolicy->check($request) === RequestPolicyInterface::ALLOW) && ($this->responsePolicy->check($response, $request) !== ResponsePolicyInterface::DENY);