diff --git a/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php index c2321c2..f6af888 100644 --- a/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php @@ -92,6 +92,15 @@ public function onRespond(FilterResponseEvent $event) { // Set the Content-language header. $response->headers->set('Content-language', $this->languageManager->getCurrentLanguage()->id); + // A cache-control header is added automatically during construction of the + // Response object. Therefore it is necessary to compare the actual value of + // the header with the default value in order to determine whether it was + // set explicitely throughout the request. Note that this header also is set + // whenever one of the Etag, Expires and Last-Modified headers is set. See + // also: + // \Symfony\Component\HttpFoundation\ResponseHeaderBag::computeCacheControlValue() + $has_custom_cache_control = ($response->headers->get('Cache-Control') != 'no-cache'); + // Because pages are highly dynamic, set the last-modified time to now // since the page is in fact being regenerated right now. // @todo Remove this and use a more intelligent default so that HTTP @@ -138,6 +147,11 @@ public function onRespond(FilterResponseEvent $event) { $max_age = $this->config->get('cache.page.max_age'); $this->pageCachePolicy->applyToResponse($response, $request); if ($max_age > 0 && $this->pageCachePolicy->isCacheable()) { + // Only record the Cache-Control header along with the cache object when + // it was explicitely set during the request. + if (!$has_custom_cache_control) { + $response->headers->remove('Cache-Control'); + } $this->internalPageCache->record($response, $request); } else { diff --git a/core/lib/Drupal/Core/PageCache/InternalPageCache.php b/core/lib/Drupal/Core/PageCache/InternalPageCache.php index f7320fb..f07515e 100644 --- a/core/lib/Drupal/Core/PageCache/InternalPageCache.php +++ b/core/lib/Drupal/Core/PageCache/InternalPageCache.php @@ -242,13 +242,6 @@ protected function set(Response $response, Request $request) { // Check if the current page may be compressed. $page_compressed = $this->config->get('response.gzip') && extension_loaded('zlib'); - // By default every symfony response has a "Cache-Control: no-cache" header. - // Therefore it is necessary to remove it here, otherwise it will be - // subsequently added again by populateResponse. - if ($response->headers->getCacheControlDirective('no-cache')) { - $response->headers->remove('Cache-Control'); - } - $cache = (object) array( 'cid' => $this->getCid($request), 'data' => array( diff --git a/core/modules/toolbar/lib/Drupal/toolbar/Routing/ToolbarController.php b/core/modules/toolbar/lib/Drupal/toolbar/Routing/ToolbarController.php index f757eab..772f972 100644 --- a/core/modules/toolbar/lib/Drupal/toolbar/Routing/ToolbarController.php +++ b/core/modules/toolbar/lib/Drupal/toolbar/Routing/ToolbarController.php @@ -33,7 +33,7 @@ public function subtreesJsonp() { // accesses the callback URL again (e.g., after clearing the browser cache or // when force-reloading a Drupal page). $max_age = 3600 * 24 * 365; - $response->setExpires(DateTime::createFromFormat('U', REQUEST_TIME + $max_age)); + $response->setExpires(\DateTime::createFromFormat('U', REQUEST_TIME + $max_age)); $response->setPrivate(); $response->setMaxAge($max_age);