Skip to content

Commit 3439147

Browse files
Merge branch '4.3' into 4.4
* 4.3: [Cache] fix memory leak when using PhpFilesAdapter [Yaml] Implement multiline string as scalar block for tagged values [HttpFoundation] Use `Cache-Control: must-revalidate` only if explicit lifetime has been given [FrameworkBundle] Use UserInterface to @return in getUser method [CI] Replace php7.4snapshot with php7.4 in Travis configuration [ExpressionLanguage][Node][BinaryNode] Process division by zero forward caught exception [Validator][ConstraintValidator] Stop passing unnecessary timezone argument to \DateTime add tags before processing them [MonologBridge] Fix debug processor datetime type
2 parents 1f70ac4 + 7ed7bff commit 3439147

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

ResponseHeaderBag.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -276,13 +276,13 @@ public function makeDisposition($disposition, $filename, $filenameFallback = '')
276276
*/
277277
protected function computeCacheControlValue()
278278
{
279-
if (!$this->cacheControl && !$this->has('ETag') && !$this->has('Last-Modified') && !$this->has('Expires')) {
280-
return 'no-cache, private';
281-
}
282-
283279
if (!$this->cacheControl) {
280+
if ($this->has('Last-Modified') || $this->has('Expires')) {
281+
return 'private, must-revalidate'; // allows for heuristic expiration (RFC 7234 Section 4.2.2) in the case of "Last-Modified"
282+
}
283+
284284
// conservative by default
285-
return 'private, must-revalidate';
285+
return 'no-cache, private';
286286
}
287287

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

Tests/ResponseHeaderBagTest.php

Lines changed: 2 additions & 2 deletions
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)