8000 minor #22099 HttpCache: New test for revalidating responses with an e… · symfony/symfony@f9b64a2 · GitHub
[go: up one dir, main page]

Skip to content

Commit f9b64a2

Browse files
committed
minor #22099 HttpCache: New test for revalidating responses with an expired TTL (mpdude)
This PR was squashed before being merged into the 2.7 branch (closes #22099). Discussion ---------- HttpCache: New test for revalidating responses with an expired TTL | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | See #22035, in particular [this and the following comments](#22035 (comment)). Commits ------- 067ab52 HttpCache: New test for revalidating responses with an expired TTL
2 parents bca4778 + 067ab52 commit f9b64a2

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,42 @@ public function testValidatesCachedResponsesWithETagAndNoFreshnessInformation()
849849
$this->assertTraceNotContains('miss');
850850
}
851851

852+
public function testServesResponseWhileFreshAndRevalidatesWithLastModifiedInformation()
853+
{
854+
$time = \DateTime::createFromFormat('U', time());
855+
856+
$this->setNextResponse(200, array(), 'Hello World', function (Request $request, Response $response) use ($time) {
857+
$response->setSharedMaxAge(10);
858+
$response->headers->set('Last-Modified', $time->format(DATE_RFC2822));
859+
});
860+
861+
// prime the cache
862+
$this->request('GET', '/');
863+
864+
// next request before s-maxage has expired: Serve from cache
865+
// without hitting the backend
866+
$this->request('GET', '/');
867+
$this->assertHttpKernelIsNotCalled();
868+
$this->assertEquals(200, $this->response->getStatusCode());
869+
$this->assertEquals('Hello World', $this->response->getContent());
870+
$this->assertTraceContains('fresh');
871+
872+
sleep(15); // expire the cache
873+
874+
$that = $this;
875+
876+
$this->setNextResponse(304, array(), '', function (Request $request, Response $response) use ($time, $that) {
877+
$that->assertEquals($time->format(DATE_RFC2822), $request->headers->get('IF_MODIFIED_SINCE'));
878+
});
879+
880+
$this->request('GET', '/');
881+
$this->assertHttpKernelIsCalled();
882+
$this->assertEquals(200, $this->response->getStatusCode());
883+
$this->assertEquals('Hello World', $this->response->getContent());
884+
$this->assertTraceContains('stale');
885+
$this->assertTraceContains('valid');
886+
}
887+
852888
public function testReplacesCachedResponsesWhenValidationResultsInNon304Response()
853889
{
854890
$time = \DateTime::createFromFormat('U', time());

0 commit comments

Comments
 (0)
0