diff -u b/core/modules/page_cache/src/StackMiddleware/PageCache.php b/core/modules/page_cache/src/StackMiddleware/PageCache.php --- b/core/modules/page_cache/src/StackMiddleware/PageCache.php +++ b/core/modules/page_cache/src/StackMiddleware/PageCache.php @@ -81,7 +81,6 @@ } else { $response = $this->pass($request, $type, $catch); - $response->headers->set(self::HEADER, 'UNCACHEABLE (request policy)'); } return $response; @@ -89,6 +88,7 @@ } else { $response = $this->pass($request, $type, $catch); + $response->headers->set(self::HEADER, 'UNCACHEABLE (request policy)'); } return $response; @@ -121,14 +121,14 @@ */ protected function lookup(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE) { if ($response = $this->get($request)) { - $response->headers->set(static::HEADER, 'HIT'); + $response->headers->set('X-Drupal-Cache', 'HIT'); } else { $response = $this->fetch($request, $type, $catch); */ protected function lookup(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE) { if ($response = $this->get($request)) { - $response->headers->set('X-Drupal-Cache', 'HIT'); + $response->headers->set(static::HEADER, 'HIT'); } else { $response = $this->fetch($request, $type, $catch); @@ -192,14 +192,14 @@ // Only set the 'X-Drupal-Cache' header if caching is allowed for this // response. if ($this->storeResponse($request, $response)) { - $response->headers->set(static::HEADER, 'MISS'); + $response->headers->set('X-Drupal-Cache', 'MISS'); } return $response; // Only set the 'X-Drupal-Cache' header if caching is allowed for this // response. if ($this->storeResponse($request, $response)) { - $response->headers->set('X-Drupal-Cache', 'MISS'); + $response->headers->set(static::HEADER, 'MISS'); } return $response; @@ -231,7 +231,6 @@ // so by replacing/extending this middleware service or adding another // one. if (!$response instanceof CacheableResponseInterface) { - $response->headers->set(self::HEADER, 'UNCACHEABLE (no cacheability)'); return FALSE; } @@ -239,13 +238,13 @@ // so by replacing/extending this middleware service or adding another // one. if (!$response instanceof CacheableResponseInterface) { + $response->headers->set(self::HEADER, 'UNCACHEABLE (no cacheability)'); return FALSE; } // Allow policy rules to further restrict which responses to cache. if ($this->responsePolicy->check($response, $request) === ResponsePolicyInterface::DENY) { - $response->headers->set(self::HEADER, 'UNCACHEABLE (response policy)'); return FALSE; } @@ -253,6 +252,7 @@ // Allow policy rules to further restrict which responses to cache. if ($this->responsePolicy->check($response, $request) === ResponsePolicyInterface::DENY) { + $response->headers->set(self::HEADER, 'UNCACHEABLE (response policy)'); return FALSE; } diff -u b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php --- b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php @@ -485,7 +485,7 @@ else { $this->assertResourceErrorResponse(403, FALSE, $response, $expected_403_cacheability->getCacheTags(), $expected_403_cacheability->getCacheContexts(), static::$auth ? FALSE : 'MISS', 'MISS'); } - $this->assertSame(static::$auth ? ['UNCACHEABLE (request policy)'] : ['MISS'], $response->getHeader('X-Drupal-Cache')); + $this->assertSame(static::$auth ? [] : ['MISS'], $response->getHeader('X-Drupal-Cache')); // DX: 403 because unauthorized. $url->setOption('query', ['_format' => static::$format]); $response = $this->request('GET', $url, $request_options); @@ -504,7 +504,7 @@ else { $this->assertResourceErrorResponse(403, FALSE, $response, $expected_403_cacheability->getCacheTags(), $expected_403_cacheability->getCacheContexts(), static::$auth ? FALSE : 'MISS', FALSE); } - $this->assertSame(static::$auth ? [] : ['MISS'], $response->getHeader('X-Drupal-Cache')); + $this->assertSame(static::$auth ? ['UNCACHEABLE (request policy)'] : ['MISS'], $response->getHeader('X-Drupal-Cache')); // DX: 403 because unauthorized. $url->setOption('query', ['_format' => static::$format]); $response = $this->request('GET', $url, $request_options); reverted: --- b/core/modules/system/src/Tests/System/ErrorHandlerTest.php +++ a/core/modules/system/src/Tests/System/ErrorHandlerTest.php @@ -170,7 +170,7 @@ ->save(); $this->drupalGet('error-test/trigger-exception'); + $this->assertFalse($this->drupalGetHeader('X-Drupal-Cache')); - $this->assertIdentical('UNCACHEABLE (no cacheability)', $this->drupalGetHeader('X-Drupal-Cache')); $this->assertIdentical(strpos($this->drupalGetHeader('Cache-Control'), 'public'), FALSE, 'Received expected HTTP status line.'); $this->assertTrue(strpos($this->drupalGetHeader(':status'), '500 Service unavailable (with message)'), 'Received expected HTTP status line.'); $this->assertNoErrorMessage($error_exception); only in patch2: unchanged: --- a/core/modules/system/tests/src/Functional/System/ErrorHandlerTest.php +++ b/core/modules/system/tests/src/Functional/System/ErrorHandlerTest.php @@ -136,7 +136,7 @@ public function testExceptionHandler() { ->save(); $this->drupalGet('error-test/trigger-exception'); - $this->assertFalse($this->drupalGetHeader('X-Drupal-Cache')); + $this->assertIdentical('UNCACHEABLE (no cacheability)', $this->drupalGetHeader('X-Drupal-Cache')); $this->assertIdentical(strpos($this->drupalGetHeader('Cache-Control'), 'public'), FALSE, 'Received expected HTTP status line.'); $this->assertSession()->statusCodeEquals(500); $this->assertNoErrorMessage($error_exception);