Skip to content

[HttpKernel] HttpCache\Store does not return response body correctly #37174

Closed
@sgehrig

Description

@sgehrig

Symfony version(s) affected: 4.4.* / 5.0.* / 5.1.* (probably others)

Description
While using Symfony\Component\HttpClient\CachingHttpClient with a Symfony\Component\HttpKernel\HttpCache\Store we found that responses returned from the cache did not yield the correct response bodies.

I checked the source and found the following snippet:

if (file_exists($body = $this->getPath($headers['x-content-digest'][0]))) {
return $this->restoreResponse($headers, $body);
}

This seems rather odd to me because after executing $body = $this->getPath($headers['x-content-digest'][0]) $body contains the path to the cached response body file and not the cached response body itself. But $body (containing the path and not the response body) is then fed into Symfony\Component\HttpKernel\HttpCache\Store::restoreResponse() where it's used to populate the Symfony\Component\HttpFoundation\Response content. So the returned response contains the path to the cached response body file in its body instead of the actual response content.

How to reproduce
Just use a Symfony\Component\HttpClient\CachingHttpClient configured with a Symfony\Component\HttpKernel\HttpCache\Store and fetch the same HTTP resource twice.

Possible Solution
I might be wrong, but to me it looks like there's a file_get_contents() missing.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions