Skip to content

Commit 84edb54

Browse files
Merge branch '4.4' into 5.0
* 4.4: [DI] Fix EnvVar not loaded when Loader requires an env var Fixed #34713 Move new messages to intl domain when possible [FrameworkBundle] Fix small typo in output comment chown and chgrp should also accept int as owner and group Revert "Fixed translations file dumper behavior" Fix RememberMe with null password [Validator] Fix plurals for sr_Latn (Serbian language written in latin script) validation messages Set booted flag to false when test kernel is unset [FrameworkBundle] remove messenger cache if not enabled [PhpUnitBridge][SymfonyTestsListenerTrait] Remove some unneeded code [HttpClient] Fix strict parsing of response status codes fix PHP const mapping keys using the inline notation [SecurityBundle] Drop duplicated code [FrameworkBundle] Make sure one can use fragments.hinclude_default_template Fix that no-cache requires positive validation with the origin, even for fresh responses Improve upgrading instructions for deprecated router options [DI] Suggest typed argument when binding fails with untyped argument
2 parents d554567 + 0fce877 commit 84edb54

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

HttpCache/HttpCache.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,10 @@ protected function lookup(Request $request, bool $catch = false)
350350
return $this->validate($request, $entry, $catch);
351351
}
352352

353+
if ($entry->headers->hasCacheControlDirective('no-cache')) {
354+
return $this->validate($request, $entry, $catch);
355+
}
356+
353357
$this->record($request, 'fresh');
354358

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

Tests/HttpCache/HttpCacheTest.php

Lines 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)