bug #19397 [2.7] [HttpFoundation] HttpCache refresh stale responses containing an ETag (maennchen)
This PR was merged into the 2.7 branch.
Discussion
----------
[2.7] [HttpFoundation] HttpCache refresh stale responses containing an ETag
| Q | A
| ------------- | ---
| Branch? | 2.7
| Bug fix? | yes
| New feature? |no
| BC breaks? |no
| Deprecations? |no
| Tests pass? | yes
| Fixed tickets | #19390, #6746
| License | MIT
| Doc PR |
This PR is the replacement of #19391, which points at the wrong branch.
Commits
-------
96df6b9
[HttpFoundation] HttpCache refresh stale responses containing an ETag
This commit is contained in:
commit
f6a77a1a3e
@ -600,6 +600,9 @@ class HttpCache implements HttpKernelInterface, TerminableInterface
|
|||||||
*/
|
*/
|
||||||
protected function store(Request $request, Response $response)
|
protected function store(Request $request, Response $response)
|
||||||
{
|
{
|
||||||
|
if (!$response->headers->has('Date')) {
|
||||||
|
$response->setDate(\DateTime::createFromFormat('U', time()));
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
$this->store->write($request, $response);
|
$this->store->write($request, $response);
|
||||||
|
|
||||||
|
@ -181,6 +181,31 @@ class HttpCacheTest extends HttpCacheTestCase
|
|||||||
$this->assertEquals(304, $this->response->getStatusCode());
|
$this->assertEquals(304, $this->response->getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testIncrementsMaxAgeWhenNoDateIsSpecifiedEventWhenUsingETag()
|
||||||
|
{
|
||||||
|
$this->setNextResponse(
|
||||||
|
200,
|
||||||
|
array(
|
||||||
|
'ETag' => '1234',
|
||||||
|
'Cache-Control' => 'public, s-maxage=60',
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->request('GET', '/');
|
||||||
|
$this->assertHttpKernelIsCalled();
|
||||||
|
$this->assertEquals(200, $this->response->getStatusCode());
|
||||||
|
$this->assertTraceContains('miss');
|
||||||
|
$this->assertTraceContains('store');
|
||||||
|
|
||||||
|
sleep(2);
|
||||||
|
|
||||||
|
$this->request('GET', '/');
|
||||||
|
$this->assertHttpKernelIsNotCalled();
|
||||||
|
$this->assertEquals(200, $this->response->getStatusCode());
|
||||||
|
$this->assertTraceContains('fresh');
|
||||||
|
$this->assertEquals(2, $this->response->headers->get('Age'));
|
||||||
|
}
|
||||||
|
|
||||||
public function testValidatesPrivateResponsesCachedOnTheClient()
|
public function testValidatesPrivateResponsesCachedOnTheClient()
|
||||||
{
|
{
|
||||||
$this->setNextResponse(200, array(), '', function ($request, $response) {
|
$this->setNextResponse(200, array(), '', function ($request, $response) {
|
||||||
|
Reference in New Issue
Block a user