-
Notifications
You must be signed in to change notification settings - Fork 123
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
Application JSON Requests Do Not Honor X-Magento-Vary Cookie #730
Comments
PR #731 |
Hi @kavingas , Thanks for providing this very detailed issue. Upon review, we aren't sure in which scenarios that API calls from the plugin would lead to a non-cached response. Can you provide some use cases / examples that are being solved for here? |
Yes it will impact any AJAX call with json response type. |
Thanks for this context, we'll review further. |
Hey @rcaril , I am following up to check the status on this one as customer is awaiting resolution, and it would help if we have an ETA. Thank You! |
Hi @kavingas - we tested the API call above on few of the shops that we maintain - one of them uses Fastly, others use Varnish. We are confident that none of them cache this API ( on the store with Fastly we can even see MISS, MISS in headers, response time isn't decreasing after repeated request) so we are not exactly sure how Vary helps them in this scenario. We don't believe that the results for their website will be any different after with this PR change. |
@rcaril Did you try with multiple store views with multiple currency setup ? |
Title
Application JSON Requests Do Not Honor
Vary
CookieDescription
While reviewing the behavior of the Fastly VCL in the Magento 2 extension, I noticed that application JSON requests are not honoring the
Vary
cookie.Currently, the logic in
[fetch.vcl](https://github.com/fastly/fastly-magento2/blob/master/etc/vcl_snippets/fetch.vcl#L67)
only addsVary
cookies fortext/html
andtext/xml
content types. As a result, JSON responses are not varying by cookie values, which can lead to serving cached data that does not match the user's session or preferences.Steps to Reproduce
application/json
request to the Magento API endpoint via Fastly.Vary
header is not set in the response.Expected Behavior
The
Vary
cookie should be applied toapplication/json
content types, ensuring correct cache variation based on user session or other cookies.Actual Behavior
The
Vary
cookie is omitted forapplication/json
responses.Relevant Code Snippet
The logic in
[fetch.vcl](https://github.com/fastly/fastly-magento2/blob/master/etc/vcl_snippets/fetch.vcl#L67)
:This restricts
Vary
cookies to only HTML and XML content types.Proposed Solution
Update the
fetch.vcl
logic to includeapplication/json
in the content types that apply theVary
cookie:Environment
Additional Context
This behavior could cause issues when serving cached JSON content for APIs that depend on user-specific data. Adding support for the
Vary
cookie in JSON responses would improve consistency and prevent user-specific cache mismatches.The text was updated successfully, but these errors were encountered: