Skip to content

[Cache] "vary" prop from Cache attribute doesn't work when inferring Locale from Accept-Language #58663

Closed as not planned
@cdaguerre

Description

@cdaguerre

Symfony version(s) affected

7.1.0

Description

Cache attribute's vary property is silently ignored with following config:

framework:
  set_locale_from_accept_language: true

And following controller

use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpKernel\Attribute\Cache;

class SomeController
{
    #[Cache(smaxage: 3600, vary: ['X-Some-Header'])]
    public function index(): Response
    {
         return new JsonResponse("OK");
    }
}

The LocaleListener adds an attribute to the request that is used by the ResponseListener to add a Vary: Accept-Language header.
However, this occurs before the CacheAttributeListener, which doesn't take the attribute's vary property into account if there is already a Vary header on the response.

Is this expected?

How to reproduce

See above.

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