diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 583d3b1..a704ebf 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -1647,6 +1647,9 @@ function _drupal_bootstrap_page_cache() { $response->send(); exit; } + else { + drupal_add_http_header('X-Drupal-Cache', 'MISS'); + } } } diff --git a/core/includes/common.inc b/core/includes/common.inc index cc723a0..eb974a5 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -13,6 +13,8 @@ use Drupal\Core\Language\Language; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\BinaryFileResponse; +use Symfony\Component\HttpFoundation\StreamedResponse; use Symfony\Component\Yaml\Parser; use Symfony\Component\Yaml\Exception\ParseException; use Drupal\Component\PhpStorage\PhpStorageFactory; @@ -2982,7 +2984,7 @@ function _drupal_bootstrap_full($skip = FALSE) { * @see drupal_page_header() */ function drupal_page_set_cache(Response $response, Request $request) { - if (drupal_page_is_cacheable()) { + if (drupal_page_is_cacheable() && !$response instanceof BinaryFileResponse && !$response instanceof StreamedResponse) { // Check if the current page may be compressed. $page_compressed = \Drupal::config('system.performance')->get('response.gzip') && extension_loaded('zlib'); @@ -3003,6 +3005,12 @@ function drupal_page_set_cache(Response $response, Request $request) { $cache->data['headers'] = $response->headers->all(); + // Hack: exclude the x-drupal-cache header; it may make it in here because + // of awkwardness in how we defer sending it over in _drupal_page_get_cache. + if (isset($cache->data['headers']['x-drupal-cache'])) { + unset($cache->data['headers']['x-drupal-cache']); + } + // Use the actual timestamp from an Expires header, if available. if ($date = $response->getExpires()) { $date = DrupalDateTime::createFromDateTime($date); diff --git a/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php index f4cd517..8e4596f 100644 --- a/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php @@ -9,7 +9,6 @@ use Drupal\Core\Language\Language; use Drupal\Core\Language\LanguageManager; -use Symfony\Component\HttpFoundation\BinaryFileResponse; use Symfony\Component\HttpKernel\Event\FilterResponseEvent; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpKernel\HttpKernelInterface; @@ -102,9 +101,7 @@ public function onRespond(FilterResponseEvent $event) { } $max_age = \Drupal::config('system.performance')->get('cache.page.max_age'); - $is_binary_file_response = ($response instanceof BinaryFileResponse); - if ($max_age > 0 && !$is_binary_file_response && ($cache = drupal_page_set_cache($response, $request))) { - $response->headers->set('X-Drupal-Cache', 'MISS'); + if ($max_age > 0 && ($cache = drupal_page_set_cache($response, $request))) { drupal_serve_page_from_cache($cache, $response, $request); } else {