Fix that no-cache requires positive validation with the origin, even for fresh responses
This commit is contained in:
parent
d1e31a4fe0
commit
c8bdcb3408
@ -323,6 +323,10 @@ class HttpCache implements HttpKernelInterface, TerminableInterface
|
|||||||
return $this->validate($request, $entry, $catch);
|
return $this->validate($request, $entry, $catch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($entry->headers->hasCacheControlDirective('no-cache')) {
|
||||||
|
return $this->validate($request, $entry, $catch);
|
||||||
|
}
|
||||||
|
|
||||||
$this->record($request, 'fresh');
|
$this->record($request, 'fresh');
|
||||||
|
|
||||||
$entry->headers->set('Age', $entry->getAge());
|
$entry->headers->set('Age', $entry->getAge());
|
||||||
|
@ -443,6 +443,22 @@ class HttpCacheTest extends HttpCacheTestCase
|
|||||||
$this->assertTrue($this->response->headers->has('Age'));
|
$this->assertTrue($this->response->headers->has('Age'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testRevalidatesResponsesWithNoCacheDirectiveEvenIfFresh()
|
||||||
|
{
|
||||||
|
$this->setNextResponse(200, ['Cache-Control' => 'public, no-cache, max-age=10', 'ETag' => 'some-etag'], 'OK');
|
||||||
|
$this->request('GET', '/'); // warm the cache
|
||||||
|
|
||||||
|
sleep(5);
|
||||||
|
|
||||||
|
$this->setNextResponse(304, ['Cache-Control' => 'public, no-cache, max-age=10', 'ETag' => 'some-etag']);
|
||||||
|
$this->request('GET', '/');
|
||||||
|
|
||||||
|
$this->assertHttpKernelIsCalled(); // no-cache -> MUST have revalidated at origin
|
||||||
|
$this->assertTraceContains('valid');
|
||||||
|
$this->assertEquals('OK', $this->response->getContent());
|
||||||
|
$this->assertEquals(0, $this->response->getAge());
|
||||||
|
}
|
||||||
|
|
||||||
public function testCachesResponsesWithAnExpirationHeader()
|
public function testCachesResponsesWithAnExpirationHeader()
|
||||||
{
|
{
|
||||||
$time = \DateTime::createFromFormat('U', time() + 5);
|
$time = \DateTime::createFromFormat('U', time() + 5);
|
||||||
|
Reference in New Issue
Block a user