Open
Description
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