Skip to content

[HttpKernel] [HttpCache] Don't throw on 304 Not Modified #43998

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 20, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function handle(HttpCache $cache, $uri, $alt, $ignoreErrors)
try {
$response = $cache->handle($subRequest, HttpKernelInterface::SUB_REQUEST, true);

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

Expand Down
9 changes: 9 additions & 0 deletions src/Symfony/Component/HttpKernel/Tests/HttpCache/EsiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,15 @@ public function testHandleWhenResponseIsNot200AndAltIsPresent()
$this->assertEquals('bar', $esi->handle($cache, '/', '/alt', false));
}

public function testHandleWhenResponseIsNotModified()
{
$esi = new Esi();
$response = new Response('');
$response->setStatusCode(304);
$cache = $this->getCache(Request::create('/'), $response);
$this->assertEquals('', $esi->handle($cache, '/', '/alt', true));
}

protected function getCache($request, $response)
{
$cache = $this->getMockBuilder(HttpCache::class)->setMethods(['getRequest', 'handle'])->disableOriginalConstructor()->getMock();
Expand Down