fix: prevent caching during vary transition#127
Open
furan917 wants to merge 1 commit into
Open
Conversation
Author
|
I think the delay on the grace.vtc needs a slightly larger delay than 2s, the varnish:fresh is pulling in varnish v9 so probably quicker. |
Collaborator
|
Language switches and other things that change the vary cookie should never happen on GET or HEAD requests. It's best to refrain from trying to fix bad architecture in a widely used VCL. It would be the start of chaos. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a visitor switches currency or language (or other vary object someone may set), Magento issues a new X-Magento-Vary cookie value. Varnish would strip the Set-Cookie header and cache the response regardless, meaning the browser never received the updated cookie and subsequent requests continued hitting the wrong cached variant for their old context and poisoning cache for others.
This change detects when the X-Magento-Vary value the backend wants to set differs from the one the visitor sent, marks the response uncacheable, and passes Set-Cookie through to the browser so it receives the correct vary hash. Normal requests where the vary value is unchanged are unaffected.
A VTC test covers all four scenarios: vary unchanged, vary changed, first-time visitor (no existing vary cookie), and vary present in the request with no Set-Cookie in the response.