diff --git a/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php index 4728c52..f7d513b 100644 --- a/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php @@ -123,6 +123,14 @@ public function onRespond(FilterResponseEvent $event) { 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; } diff --git a/core/modules/image/src/Controller/ImageStyleDownloadController.php b/core/modules/image/src/Controller/ImageStyleDownloadController.php index 7b67072..afb1888 100644 --- a/core/modules/image/src/Controller/ImageStyleDownloadController.php +++ b/core/modules/image/src/Controller/ImageStyleDownloadController.php @@ -123,16 +123,7 @@ public function deliver(Request $request, $scheme, ImageStyleInterface $image_st // control access to the file. if ($scheme == 'private') { if (file_exists($derivative_uri)) { - $response = parent::download($request, $scheme); - - if ($response instanceof BinaryFileResponse) { - // The expires header is usually set in the finish response subscriber - // but not for images so we're setting it here. - $response->headers->add([ - 'Expires' => \DateTime::createFromFormat('D, d M Y H:i:s T', 'Sun, 19 Nov 1978 05:00:00 GMT')->format('D, d M Y H:i:s T') - ]); - } - return $response; + return parent::download($request, $scheme); } else { $headers = $this->moduleHandler()->invokeAll('file_download', array($image_uri)); @@ -183,12 +174,9 @@ public function deliver(Request $request, $scheme, ImageStyleInterface $image_st if ($success) { $image = $this->imageFactory->get($derivative_uri); $uri = $image->getSource(); - // The expires header is usually set in the finish response subscriber - // but not for images so we're setting it here. $headers += array( 'Content-Type' => $image->getMimeType(), 'Content-Length' => $image->getFileSize(), - 'Expires' => \DateTime::createFromFormat('D, d M Y H:i:s T', 'Sun, 19 Nov 1978 05:00:00 GMT')->format('D, d M Y H:i:s T'), ); return new BinaryFileResponse($uri, 200, $headers, FALSE); }