Skip to content

[HttpCache][WIP] Use RFC9211 Cache-Status #60078

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: 7.4
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Symfony/Component/HttpFoundation/HeaderBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class HeaderBag implements \IteratorAggregate, \Countable, \Stringable
protected array $headers = [];
protected array $cacheControl = [];

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blank line can be removed

protected array $cacheStatus = [];

public function __construct(array $headers = [])
{
foreach ($headers as $key => $values) {
Expand Down
3 changes: 3 additions & 0 deletions src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,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');

Expand All @@ -345,6 +347,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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public function testInvalidatesOnPostPutDeleteRequests()

$this->assertHttpKernelIsCalled();
$this->assertResponseOk();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert

$this->assertTraceContains('invalidate');
$this->assertTraceContains('pass');
}
Expand Down Expand Up @@ -635,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());
Expand Down
Loading