Skip to content

Commit d5fb833

Browse files
mpdudefabpot
authored andcommitted
[HttpKernel] [HttpCache] Keep s-maxage=0 from ESI sub-responses
1 parent a473739 commit d5fb833

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

HttpCache/ResponseCacheStrategy.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,10 @@ public function add(Response $response)
8181
return;
8282
}
8383

84-
$this->storeRelativeAgeDirective('max-age', $response->headers->getCacheControlDirective('max-age'), $age);
85-
$this->storeRelativeAgeDirective('s-maxage', $response->headers->getCacheControlDirective('s-maxage') ?: $response->headers->getCacheControlDirective('max-age'), $age);
84+
$maxAge = $response->headers->hasCacheControlDirective('max-age') ? (int) $response->headers->getCacheControlDirective('max-age') : null;
85+
$this->storeRelativeAgeDirective('max-age', $maxAge, $age);
86+
$sharedMaxAge = $response->headers->hasCacheControlDirective('s-maxage') ? (int) $response->headers->getCacheControlDirective('s-maxage') : $maxAge;
87+
$this->storeRelativeAgeDirective('s-maxage', $sharedMaxAge, $age);
8688

8789
$expires = $response->getExpires();
8890
$expires = null !== $expires ? (int) $expires->format('U') - (int) $response->getDate()->format('U') : null;

Tests/HttpCache/ResponseCacheStrategyTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,22 @@ public function cacheControlMergingProvider()
377377
],
378378
];
379379

380+
yield 's-maxage may be set to 0' => [
381+
['public' => true, 's-maxage' => '0', 'max-age' => null],
382+
['public' => true, 's-maxage' => '0'],
383+
[
384+
['public' => true, 's-maxage' => '60'],
385+
],
386+
];
387+
388+
yield 's-maxage may be set to 0, and works independently from maxage' => [
389+
['public' => true, 's-maxage' => '0', 'max-age' => '30'],
390+
['public' => true, 's-maxage' => '0', 'max-age' => '30'],
391+
[
392+
['public' => true, 'max-age' => '60'],
393+
],
394+
];
395+
380396
yield 'result is private when combining private responses' => [
381397
['no-cache' => false, 'must-revalidate' => false, 'private' => true],
382398
['s-maxage' => 60, 'private' => true],

0 commit comments

Comments
 (0)