Skip to content

[HttpKernel] Adjust priority of CacheAttributeListener to ensure Vary header is not skipped #61368

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 6.4
Choose a base branch
from

Conversation

santysisi
Copy link
Contributor

Q A
Branch? 6.4
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #61229
License MIT

Summary

This PR updates the priority of the KernelEvents::RESPONSE event from -10 to 10 in the CacheAttributeListener.

Reason

Previously, the CacheAttributeListener was executed after the ResponseListener. When the set_locale_from_accept_language option is enabled in framework.yaml, the ResponseListener sets a Vary header on the response. Because CacheAttributeListener checks if a Vary header already exists before modifying it, its logic was being bypassed if it ran after the ResponseListener.

Fix

By increasing the event priority, we ensure the CacheAttributeListener runs before the ResponseListener, allowing it to correctly evaluate and modify the Vary header when necessary.

References

Note

I'm not sure if changing the priority of this event in this listener could have other side effects.

@carsonbot

This comment has been minimized.

@carsonbot carsonbot added this to the 7.4 milestone Aug 9, 2025
@santysisi santysisi changed the base branch from 7.4 to 6.4 August 9, 2025 00:47
@santysisi santysisi force-pushed the fix/cache-listener-priority branch from 9eec426 to 04f4315 Compare August 9, 2025 00:48
@santysisi
Copy link
Contributor Author

If we want to avoid changing the priority, we can add a condition to check whether the request has the _vary_by_language attribute set to true, and the response's Vary header contains only Accept-Language.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CacheAttributeListener overrides custom Vary headers when set_locale_from_accept_language is enabled
2 participants