Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1b1002b

Browse filesBrowse files
mpdudenicolas-grekas
authored andcommitted
[HttpFoundation] Use Cache-Control: must-revalidate only if explicit lifetime has been given
1 parent 8aefe97 commit 1b1002b
Copy full SHA for 1b1002b

File tree

Expand file treeCollapse file tree

4 files changed

+7
-11
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+7
-11
lines changed
Open diff view settings
Collapse file

‎src/Symfony/Component/HttpFoundation/ResponseHeaderBag.php‎

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/ResponseHeaderBag.php
+5-5Lines changed: 5 additions & 5 deletions
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();
Collapse file

‎src/Symfony/Component/HttpFoundation/Tests/ResponseHeaderBagTest.php‎

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Tests/ResponseHeaderBagTest.php
+2-2Lines 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']);
Collapse file

‎src/Symfony/Component/HttpKernel/HttpCache/ResponseCacheStrategy.php‎

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/HttpCache/ResponseCacheStrategy.php
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ public function update(Response $response)
110110
$response->headers->set('Age', $this->age);
111111

112112
if ($this->isNotCacheableResponseEmbedded) {
113-
$response->setExpires($response->getDate());
114-
115113
if ($this->flagDirectives['no-store']) {
116114
$response->headers->set('Cache-Control', 'no-cache, no-store, must-revalidate');
117115
} else {
Collapse file

‎src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php‎

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,7 +1242,6 @@ public function testEsiCacheForceValidation()
12421242
$this->request('GET', '/', [], [], true);
12431243
$this->assertEquals('Hello World! My name is Bobby.', $this->response->getContent());
12441244
$this->assertNull($this->response->getTtl());
1245-
$this->assertTrue($this->response->mustRevalidate());
12461245
$this->assertTrue($this->response->headers->hasCacheControlDirective('private'));
12471246
$this->assertTrue($this->response->headers->hasCacheControlDirective('no-cache'));
12481247
}
@@ -1273,7 +1272,6 @@ public function testEsiCacheForceValidationForHeadRequests()
12731272
// This can neither be cached nor revalidated, so it should be private/no cache
12741273
$this->assertEmpty($this->response->getContent());
12751274
$this->assertNull($this->response->getTtl());
1276-
$this->assertTrue($this->response->mustRevalidate());
12771275
$this->assertTrue($this->response->headers->hasCacheControlDirective('private'));
12781276
$this->assertTrue($this->response->headers->hasCacheControlDirective('no-cache'));
12791277
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.