Skip to content

Commit 723b5ca

Browse files
mpdudenicolas-grekas
authored andcommitted
[HttpFoundation] Use Cache-Control: must-revalidate only if explicit lifetime has been given
1 parent d2d0cfe commit 723b5ca

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

ResponseHeaderBag.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -309,13 +309,13 @@ public function makeDisposition($disposition, $filename, $filenameFallback = '')
309309
*/
310310
protected function computeCacheControlValue()
311311
{
312-
if (!$this->cacheControl && !$this->has('ETag') && !$this->has('Last-Modified') && !$this->has('Expires')) {
313-
return 'no-cache, private';
314-
}
315-
316312
if (!$this->cacheControl) {
313+
if ($this->has('Last-Modified') || $this->has('Expires')) {
314+
return 'private, must-revalidate'; // allows for heuristic expiration (RFC 7234 Section 4.2.2) in the case of "Last-Modified"
315+
}
316+
317317
// conservative by default
318-
return 'private, must-revalidate';
318+
return 'no-cache, private';
319319
}
320320

321321
$header = $this->getCacheControlHeader();

Tests/ResponseHeaderBagTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ public function testCacheControlHeader()
5151
$this->assertTrue($bag->hasCacheControlDirective('public'));
5252

5353
$bag = new ResponseHeaderBag(['ETag' => 'abcde']);
54-
$this->assertEquals('private, must-revalidate', $bag->get('Cache-Control'));
54+
$this->assertEquals('no-cache, private', $bag->get('Cache-Control'));
5555
$this->assertTrue($bag->hasCacheControlDirective('private'));
56-
$this->assertTrue($bag->hasCacheControlDirective('must-revalidate'));
56+
$this->assertTrue($bag->hasCacheControlDirective('no-cache'));
5757
$this->assertFalse($bag->hasCacheControlDirective('max-age'));
5858

5959
$bag = new ResponseHeaderBag(['Expires' => 'Wed, 16 Feb 2011 14:17:43 GMT']);

0 commit comments

Comments
 (0)