Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Inconsistent response headers when using caching via Cache attribute #58598

Copy link
Copy link
Open
@EugeniyPetrov

Description

@EugeniyPetrov
Issue body actions

Symfony version(s) affected

7.1.5

Description

When HTTP caching is set using #[Cache] attribute, and only if HTTP/1.0 (which is the default protocol nginx uses to request upstream when configured as reverse proxy) is used, symfony adds headers that prevent response from being cached.

How to reproduce

#[Route('/test1', name: 'test1')]
public function test1(): Response
{
    return (new Response("Hello\n"))
        ->setPublic()
        ->setMaxAge(31536000);
}

#[Route('/test2', name: 'test2')]
#[Cache(maxage: 31536000, public: true)]
public function test2(): Response
{
    return new Response("Hello\n");
}
$ curl --http1.0 -i 'http://127.0.0.1:8002/test1'
HTTP/1.0 200 OK
Cache-Control: max-age=31536000, public
Content-Type: text/html; charset=UTF-8
Date: Fri, 18 Oct 2024 10:37:32 GMT
X-Powered-By: PHP/8.3.10
Content-Length: 6

Hello

$ curl --http1.0 -i 'http://127.0.0.1:8002/test2'
HTTP/1.0 200 OK
Cache-Control: max-age=31536000, public
Content-Type: text/html; charset=UTF-8
Date: Fri, 18 Oct 2024 10:37:33 GMT
Expires: -1                                         <-- prevents caching
Pragma: no-cache                                    <--
X-Powered-By: PHP/8.3.10
Content-Length: 6

Hello

Possible Solution

No response

Additional Context

No response

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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.