[HttpKernel] [HttpCache] Keep s-maxage=0 from ESI sub-responses

This commit is contained in:
Matthias Pigulla 2021-06-10 20:42:23 +00:00 committed by Fabien Potencier
parent 0fa07c6d7c
commit ee7bc0272e
2 changed files with 20 additions and 2 deletions

View File

@ -81,8 +81,10 @@ class ResponseCacheStrategy implements ResponseCacheStrategyInterface
return;
}
$this->storeRelativeAgeDirective('max-age', $response->headers->getCacheControlDirective('max-age'), $age);
$this->storeRelativeAgeDirective('s-maxage', $response->headers->getCacheControlDirective('s-maxage') ?: $response->headers->getCacheControlDirective('max-age'), $age);
$maxAge = $response->headers->hasCacheControlDirective('max-age') ? (int) $response->headers->getCacheControlDirective('max-age') : null;
$this->storeRelativeAgeDirective('max-age', $maxAge, $age);
$sharedMaxAge = $response->headers->hasCacheControlDirective('s-maxage') ? (int) $response->headers->getCacheControlDirective('s-maxage') : $maxAge;
$this->storeRelativeAgeDirective('s-maxage', $sharedMaxAge, $age);
$expires = $response->getExpires();
$expires = null !== $expires ? (int) $expires->format('U') - (int) $response->getDate()->format('U') : null;

View File

@ -377,6 +377,22 @@ class ResponseCacheStrategyTest extends TestCase
],
];
yield 's-maxage may be set to 0' => [
['public' => true, 's-maxage' => '0', 'max-age' => null],
['public' => true, 's-maxage' => '0'],
[
['public' => true, 's-maxage' => '60'],
],
];
yield 's-maxage may be set to 0, and works independently from maxage' => [
['public' => true, 's-maxage' => '0', 'max-age' => '30'],
['public' => true, 's-maxage' => '0', 'max-age' => '30'],
[
['public' => true, 'max-age' => '60'],
],
];
yield 'result is private when combining private responses' => [
['no-cache' => false, 'must-revalidate' => false, 'private' => true],
['s-maxage' => 60, 'private' => true],