Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c8bdcb3

Browse filesBrowse files
committed
Fix that no-cache requires positive validation with the origin, even for fresh responses
1 parent d1e31a4 commit c8bdcb3
Copy full SHA for c8bdcb3

File tree

2 files changed

+20
-0
lines changed
Filter options

2 files changed

+20
-0
lines changed

‎src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,10 @@ protected function lookup(Request $request, $catch = false)
323323
return $this->validate($request, $entry, $catch);
324324
}
325325

326+
if ($entry->headers->hasCacheControlDirective('no-cache')) {
327+
return $this->validate($request, $entry, $catch);
328+
}
329+
326330
$this->record($request, 'fresh');
327331

328332
$entry->headers->set('Age', $entry->getAge());

‎src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,22 @@ public function testCachesResponsesWithExplicitNoCacheDirective()
443443
$this->assertTrue($this->response->headers->has('Age'));
444444
}
445445

446+
public function testRevalidatesResponsesWithNoCacheDirectiveEvenIfFresh()
447+
{
448+
$this->setNextResponse(200, ['Cache-Control' => 'public, no-cache, max-age=10', 'ETag' => 'some-etag'], 'OK');
449+
$this->request('GET', '/'); // warm the cache
450+
451+
sleep(5);
452+
453+
$this->setNextResponse(304, ['Cache-Control' => 'public, no-cache, max-age=10', 'ETag' => 'some-etag']);
454+
$this->request('GET', '/');
455+
456+
$this->assertHttpKernelIsCalled(); // no-cache -> MUST have revalidated at origin
457+
$this->assertTraceContains('valid');
458+
$this->assertEquals('OK', $this->response->getContent());
459+
$this->assertEquals(0, $this->response->getAge());
460+
}
461+
446462
public function testCachesResponsesWithAnExpirationHeader()
447463
{
448464
$time = \DateTime::createFromFormat('U', time() + 5);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.