-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Description
Symfony version(s) affected
>=7.4
Description
The Vary
header(s), defined with the @Cache
attributes are ignored when used in conjunction with the feature set_locale_from_accept_language
.
However, the documentation doesn't mention any impact on Vary
response header enabling this feature:
If this option is set to true, the Request locale will automatically be set to the value of the Accept-Language HTTP header.
When the _locale request attribute is passed, the Accept-Language header is ignored.
The possible cause is at this line, looks like the Symfony\Component\HttpKernel\EventListener\CacheAttributeListener
listener overwrites the Vary
header(s) passed by @Cache
attributes, instead of adding to it — which may break expected behavior when custom Vary headers are required.
How to reproduce
./src/Controller/TestController.php
<?php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\Cache;
class TestController
{
#[Cache(vary: ['X-Custom-Header'], public: true)]
public function __invoke(): Response
{
return new Response('Hello world');
}
}
./config/packages/framework.yaml
framework:
set_locale_from_accept_language: true
curl --location 'http://localhost:8000/test'
Vary response header: Accept-Language
Possible Solution
No response
Additional Context
No response