8000 [HttpKernel] Improve and add tests for `Last-Modified` computation with ESI responses by mpdude · Pull Request #58011 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[HttpKernel] Improve and add tests for Last-Modified computation with ESI responses #58011

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

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -138,22 +138,48 @@ public function testLastModifiedIsMergedWithEmbeddedResponse()
{
$cacheStrategy = new ResponseCacheStrategy();

$mainResponse = new Response();
$mainResponse->setLastModified(new \DateTimeImmutable('-2 hour'));

$embeddedDate = new \DateTimeImmutable('-1 hour');
$embeddedResponse = new Response();
$embeddedResponse->setLastModified($embeddedDate);

// This master response uses the "validation" model
$masterResponse = new Response();
$masterResponse->setLastModified(new \DateTimeImmutable('-2 hour'));
$masterResponse->setEtag('foo');
$cacheStrategy->add($embeddedResponse);
$cacheStrategy->update($mainResponse);

$this->assertTrue($mainResponse->headers->has('Last-Modified'));
$this->assertSame($embeddedDate->getTimestamp(), $mainResponse->getLastModified()->getTimestamp());
}

public function testLastModifiedIsRemovedWhenEmbeddedResponseHasNoLastModified()
{
$cacheStrategy = new ResponseCacheStrategy();

$mainResponse = new Response();
$mainResponse->setLastModified(new \DateTimeImmutable('-2 hour'));

// Embedded response uses "expiry" model
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think "expiry" refers to the maxAge, but we're only using Last-Modified in both reqests. Last-Modified is, to my understanding, one possibly way of revalidation.

$embeddedResponse = new Response();
$embeddedResponse->setLastModified($embeddedDate);

$cacheStrategy->add($embeddedResponse);
$cacheStrategy->update($mainResponse);

$this->assertFalse($mainResponse->headers->has('Last-Modified'));
}

$cacheStrategy->update($masterResponse);
public function testLastModifiedIsNotAddedWhenMainResponseHasNoLastModified()
{
$cacheStrategy = new ResponseCacheStrategy();

$this->assertTrue($masterResponse->isValidateable());
$this->assertSame($embeddedDate->getTimestamp(), $masterResponse->getLastModified()->getTimestamp());
$mainResponse = new Response();

$embeddedResponse = new Response();
$embeddedResponse->setLastModified(new \DateTimeImmutable('-2 hour'));

$cacheStrategy->add($embeddedResponse);
$cacheStrategy->update($mainResponse);

$this->assertFalse($mainResponse->headers->has('Last-Modified'));
}

public function testMainResponseIsNotCacheableWhenEmbeddedResponseIsNotCacheable()
Expand Down
0