Skip to content

Commit 705aeaa

Browse files
Merge branch '3.1'
* 3.1: [Console] Application update PHPDoc of add and register methods [Config] Extra tests for Config component Fixed bugs in names of classes and methods. [DoctrineBridge] Fixed php doc [FrameworkBundle] Fixed parameters number mismatch declaration [BrowserKit] Added test for followRedirect method (POST method) Fix the money form type render with Bootstrap3 [BrowserKit] Uppercase the "GET" method in redirects [DomCrawler] Inherit the namespace cache in subcrawlers [WebProfilerBundle] Fixed JSDoc parameter definition [HttpFoundation] HttpCache refresh stale responses containing an ETag Conflicts: src/Symfony/Component/Console/Application.php
2 parents 1b68930 + 8c0f345 commit 705aeaa

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

HttpCache/HttpCache.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,9 @@ protected function lock(Request $request, Response $entry)
580580
*/
581581
protected function store(Request $request, Response $response)
582582
{
583+
if (!$response->headers->has('Date')) {
584+
$response->setDate(\DateTime::createFromFormat('U', time()));
585+
}
583586
try {
584587
$this->store->write($request, $response);
585588

Tests/HttpCache/HttpCacheTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,31 @@ public function testRespondsWith304OnlyIfIfNoneMatchAndIfModifiedSinceBothMatch(
181181
$this->assertEquals(304, $this->response->getStatusCode());
182182
}
183183

184+
public function testIncrementsMaxAgeWhenNoDateIsSpecifiedEventWhenUsingETag()
185+
{
186+
$this->setNextResponse(
187+
200,
188+
array(
189+
'ETag' => '1234',
190+
'Cache-Control' => 'public, s-maxage=60',
191+
)
192+
);
193+
194+
$this->request('GET', '/');
195+
$this->assertHttpKernelIsCalled();
196+
$this->assertEquals(200, $this->response->getStatusCode());
197+
$this->assertTraceContains('miss');
198+
$this->assertTraceContains('store');
199+
200+
sleep(2);
201+
202+
$this->request('GET', '/');
203+
$this->assertHttpKernelIsNotCalled();
204+
$this->assertEquals(200, $this->response->getStatusCode());
205+
$this->assertTraceContains('fresh');
206+
$this->assertEquals(2, $this->response->headers->get('Age'));
207+
}
208+
184209
public function testValidatesPrivateResponsesCachedOnTheClient()
185210
{
186211
$this->setNextResponse(200, array(), '', function ($request, $response) {

0 commit comments

Comments
 (0)