diff --git a/src/Symfony/Component/HttpFoundation/HeaderBag.php b/src/Symfony/Component/HttpFoundation/HeaderBag.php index c2ede560b276f..23cabc2e67ea8 100644 --- a/src/Symfony/Component/HttpFoundation/HeaderBag.php +++ b/src/Symfony/Component/HttpFoundation/HeaderBag.php @@ -28,6 +28,7 @@ class HeaderBag implements \IteratorAggregate, \Countable, \Stringable */ protected array $headers = []; protected array $cacheControl = []; + protected array $cacheStatus = []; public function __construct(array $headers = []) { diff --git a/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php b/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php index 7b6d4c03cb5a9..cfe864a540692 100644 --- a/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php +++ b/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php @@ -341,6 +341,8 @@ protected function lookup(Request $request, bool $catch = false): Response return $this->fetch($request, $catch); } + $entry->headers->set('Cache-Status', 'SymfonyCache, hit; ttl='.$entry->getTtl()); + if (!$this->isFreshEnough($request, $entry)) { $this->record($request, 'stale'); @@ -351,6 +353,7 @@ protected function lookup(Request $request, bool $catch = false): Response return $this->validate($request, $entry, $catch); } + $this->record($request, 'hit'); $this->record($request, 'fresh'); $entry->headers->set('Age', $entry->getAge()); diff --git a/src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php b/src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php index 0f2273c2546b8..a6c2b73035af6 100644 --- a/src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php @@ -636,6 +636,8 @@ public function testHitsCachedResponseWithMaxAgeDirective() $this->assertLessThan(2, strtotime($this->responses[0]->headers->get('Date')) - strtotime($this->response->headers->get('Date'))); $this->assertGreaterThan(0, $this->response->headers->get('Age')); $this->assertNotNull($this->response->headers->get('X-Content-Digest')); + $this->assertNotNull($this->response->headers->get('Cache-Status')); + $this->assertTraceContains('hit'); $this->assertTraceContains('fresh'); $this->assertTraceNotContains('store'); $this->assertEquals('Hello World', $this->response->getContent());