Skip to content

Commit fa063a1

Browse files
committed
bug #43998 [HttpKernel] [HttpCache] Don't throw on 304 Not Modified (aleho)
This PR was merged into the 4.4 branch. Discussion ---------- [HttpKernel] [HttpCache] Don't throw on 304 Not Modified | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fixes #43997 | License | MIT | Doc PR | ~ If the response cache keeps a `Last-Modified` header clients will request with `If-Modified-Since`. The surrogate will not handle a `304 Not Modified` correctly, resulting in a 500 and a failed request. This fixes that request / response cycle, as observed in testing PR #42355. Commits ------- d27f02a [HttpKernel] [HttpCache] Don't throw on 304 Not Modified
2 parents 180eade + d27f02a commit fa063a1

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function handle(HttpCache $cache, $uri, $alt, $ignoreErrors)
9595
try {
9696
$response = $cache->handle($subRequest, HttpKernelInterface::SUB_REQUEST, true);
9797

98-
if (!$response->isSuccessful()) {
98+
if (!$response->isSuccessful() && Response::HTTP_NOT_MODIFIED !== $response->getStatusCode()) {
9999
throw new \RuntimeException(sprintf('Error when rendering "%s" (Status code is %d).', $subRequest->getUri(), $response->getStatusCode()));
100100
}
101101

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

+9
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,15 @@ public function testHandleWhenResponseIsNot200AndAltIsPresent()
221221
$this->assertEquals('bar', $esi->handle($cache, '/', '/alt', false));
222222
}
223223

224+
public function testHandleWhenResponseIsNotModified()
225+
{
226+
$esi = new Esi();
227+
$response = new Response('');
228+
$response->setStatusCode(304);
229+
$cache = $this->getCache(Request::create('/'), $response);
230+
$this->assertEquals('', $esi->handle($cache, '/', '/alt', true));
231+
}
232+
224233
protected function getCache($request, $response)
225234
{
226235
$cache = $this->getMockBuilder(HttpCache::class)->setMethods(['getRequest', 'handle'])->disableOriginalConstructor()->getMock();

0 commit comments

Comments
 (0)