[HttpFoundation] Use Cache-Control: must-revalidate
only if explicit lifetime has been given
This commit is contained in:
parent
8aefe97a89
commit
1b1002b426
@ -309,13 +309,13 @@ class ResponseHeaderBag extends HeaderBag
|
|||||||
*/
|
*/
|
||||||
protected function computeCacheControlValue()
|
protected function computeCacheControlValue()
|
||||||
{
|
{
|
||||||
if (!$this->cacheControl && !$this->has('ETag') && !$this->has('Last-Modified') && !$this->has('Expires')) {
|
|
||||||
return 'no-cache, private';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$this->cacheControl) {
|
if (!$this->cacheControl) {
|
||||||
|
if ($this->has('Last-Modified') || $this->has('Expires')) {
|
||||||
|
return 'private, must-revalidate'; // allows for heuristic expiration (RFC 7234 Section 4.2.2) in the case of "Last-Modified"
|
||||||
|
}
|
||||||
|
|
||||||
// conservative by default
|
// conservative by default
|
||||||
return 'private, must-revalidate';
|
return 'no-cache, private';
|
||||||
}
|
}
|
||||||
|
|
||||||
$header = $this->getCacheControlHeader();
|
$header = $this->getCacheControlHeader();
|
||||||
|
@ -51,9 +51,9 @@ class ResponseHeaderBagTest extends TestCase
|
|||||||
$this->assertTrue($bag->hasCacheControlDirective('public'));
|
$this->assertTrue($bag->hasCacheControlDirective('public'));
|
||||||
|
|
||||||
$bag = new ResponseHeaderBag(['ETag' => 'abcde']);
|
$bag = new ResponseHeaderBag(['ETag' => 'abcde']);
|
||||||
$this->assertEquals('private, must-revalidate', $bag->get('Cache-Control'));
|
$this->assertEquals('no-cache, private', $bag->get('Cache-Control'));
|
||||||
$this->assertTrue($bag->hasCacheControlDirective('private'));
|
$this->assertTrue($bag->hasCacheControlDirective('private'));
|
||||||
$this->assertTrue($bag->hasCacheControlDirective('must-revalidate'));
|
$this->assertTrue($bag->hasCacheControlDirective('no-cache'));
|
||||||
$this->assertFalse($bag->hasCacheControlDirective('max-age'));
|
$this->assertFalse($bag->hasCacheControlDirective('max-age'));
|
||||||
|
|
||||||
$bag = new ResponseHeaderBag(['Expires' => 'Wed, 16 Feb 2011 14:17:43 GMT']);
|
$bag = new ResponseHeaderBag(['Expires' => 'Wed, 16 Feb 2011 14:17:43 GMT']);
|
||||||
|
@ -110,8 +110,6 @@ class ResponseCacheStrategy implements ResponseCacheStrategyInterface
|
|||||||
$response->headers->set('Age', $this->age);
|
$response->headers->set('Age', $this->age);
|
||||||
|
|
||||||
if ($this->isNotCacheableResponseEmbedded) {
|
if ($this->isNotCacheableResponseEmbedded) {
|
||||||
$response->setExpires($response->getDate());
|
|
||||||
|
|
||||||
if ($this->flagDirectives['no-store']) {
|
if ($this->flagDirectives['no-store']) {
|
||||||
$response->headers->set('Cache-Control', 'no-cache, no-store, must-revalidate');
|
$response->headers->set('Cache-Control', 'no-cache, no-store, must-revalidate');
|
||||||
} else {
|
} else {
|
||||||
|
@ -1242,7 +1242,6 @@ class HttpCacheTest extends HttpCacheTestCase
|
|||||||
$this->request('GET', '/', [], [], true);
|
$this->request('GET', '/', [], [], true);
|
||||||
$this->assertEquals('Hello World! My name is Bobby.', $this->response->getContent());
|
$this->assertEquals('Hello World! My name is Bobby.', $this->response->getContent());
|
||||||
$this->assertNull($this->response->getTtl());
|
$this->assertNull($this->response->getTtl());
|
||||||
$this->assertTrue($this->response->mustRevalidate());
|
|
||||||
$this->assertTrue($this->response->headers->hasCacheControlDirective('private'));
|
$this->assertTrue($this->response->headers->hasCacheControlDirective('private'));
|
||||||
$this->assertTrue($this->response->headers->hasCacheControlDirective('no-cache'));
|
$this->assertTrue($this->response->headers->hasCacheControlDirective('no-cache'));
|
||||||
}
|
}
|
||||||
@ -1273,7 +1272,6 @@ class HttpCacheTest extends HttpCacheTestCase
|
|||||||
// This can neither be cached nor revalidated, so it should be private/no cache
|
// This can neither be cached nor revalidated, so it should be private/no cache
|
||||||
$this->assertEmpty($this->response->getContent());
|
$this->assertEmpty($this->response->getContent());
|
||||||
$this->assertNull($this->response->getTtl());
|
$this->assertNull($this->response->getTtl());
|
||||||
$this->assertTrue($this->response->mustRevalidate());
|
|
||||||
$this->assertTrue($this->response->headers->hasCacheControlDirective('private'));
|
$this->assertTrue($this->response->headers->hasCacheControlDirective('private'));
|
||||||
$this->assertTrue($this->response->headers->hasCacheControlDirective('no-cache'));
|
$this->assertTrue($this->response->headers->hasCacheControlDirective('no-cache'));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user