Thanks to visit codestin.com
Credit goes to github.com

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 3 commits 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
1 change: 1 addition & 0 deletions src/Symfony/Component/HttpFoundation/HeaderBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class HeaderBag implements \IteratorAggregate, \Countable, \Stringable
*/
protected array $headers = [];
protected array $cacheControl = [];
protected array $cacheStatus = [];
Copy link
Member

Choose a reason for hiding this comment

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

this array is unused

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, I intended to use this array later in order to separate cache status headers (in the rfc) from cache control headers. It is still a wip, but yes soon it will be used.


public function __construct(array $headers = [])
{
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 @@ -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');

Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Loading