diff --git a/core/modules/page_cache/src/StackMiddleware/PageCache.php b/core/modules/page_cache/src/StackMiddleware/PageCache.php index 1629c14..ef795c4 100644 --- a/core/modules/page_cache/src/StackMiddleware/PageCache.php +++ b/core/modules/page_cache/src/StackMiddleware/PageCache.php @@ -9,6 +9,7 @@ use Drupal\Component\Utility\UserAgent; use Drupal\Core\Cache\Cache; +use Drupal\Core\Cache\CacheableResponse; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\PageCache\RequestPolicyInterface; use Drupal\Core\PageCache\ResponsePolicyInterface; @@ -119,7 +120,8 @@ protected function pass(Request $request, $type = self::MASTER_REQUEST, $catch = * A response object. */ protected function lookup(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE) { - if ($response = $this->get($request)) { + $response = $this->get($request); + if ($response instanceof CacheableResponse) { $response->headers->set('X-Drupal-Cache', 'HIT'); } else { diff --git a/core/modules/page_cache/src/Tests/PageCacheTest.php b/core/modules/page_cache/src/Tests/PageCacheTest.php index 5f758bf..5ffcea0 100644 --- a/core/modules/page_cache/src/Tests/PageCacheTest.php +++ b/core/modules/page_cache/src/Tests/PageCacheTest.php @@ -442,12 +442,10 @@ public function testCacheableResponseResponses() { // Try to fill the cache. $this->drupalGet('/system-test/respond-reponse'); - $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'MISS', 'Page was not cached.'); $this->assertEqual($this->drupalGetHeader('Cache-Control'), 'must-revalidate, no-cache, post-check=0, pre-check=0, private', 'Cache-Control header was sent'); // Still not cached, uncacheable response. $this->drupalGet('/system-test/respond-reponse'); - $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'MISS', 'Page was not cached.'); $this->assertEqual($this->drupalGetHeader('Cache-Control'), 'must-revalidate, no-cache, post-check=0, pre-check=0, private', 'Cache-Control header was sent'); }