Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,9 @@ protected function lock(Request $request, Response $entry)
*/
protected function store(Request $request, Response $response)
{
if (!$response->headers->has('Date')) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to explicitly call setDate to clarify what the code is doing even though one line containing the following would have the same effect:

$response->getDate();

$response->setDate(\DateTime::createFromFormat('U', time()));
}
try {
$this->store->write($request, $response);

Expand Down
25 changes: 25 additions & 0 deletions src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,31 @@ public function testRespondsWith304OnlyIfIfNoneMatchAndIfModifiedSinceBothMatch(
$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()
{
$this->setNextResponse(200, array(), '', function ($request, $response) {
Expand Down