8000 [HttpCache] bug: response body is served with 304 status code · Issue #1413 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
[HttpCache] bug: response body is served with 304 status code #1413
Closed
@ghost

Description

This bug occurs when AppCache is used and the response is pulled from cache.

Serving response body with 304 status code is against HTTP spec.

This bug can be fixed here:

diff --git a/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php b/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php
index 705e762..78960a2 100644
--- a/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php
+++ b/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php
@@ -550,7 +550,7 @@ class HttpCache implements HttpKernelInterface
      */
     private function restoreResponseBody(Request $request, Response $response)
     {
-        if ('head' === strtolower($request->getMethod())) {
+        if ('head' === strtolower($request->getMethod()) || 304 == $response->getStatusCode()) {
             $response->setContent('');
             $response->headers->remove('X-Body-Eval');
             $response->headers->remove('X-Body-File');

but the solution will need some unit testing

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0