-
-
Notifications
You must be signed in to change notification settings - Fork 356
[Turbo] Add Vary header for stream responses in docs #215
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
Conversation
dunglas
commented
Jan 11, 2022
Q | A |
---|---|
Bug fix? | no |
New feature? | no |
Tickets | n/a |
License | MIT |
// The same URL will return a response with a different Content-Type HTTP header | ||
// depending on the Accept request header. | ||
// To prevent cache pollution issues, we must set the Vary response header. | ||
#[Cache(vary: ['Accept'])] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but this is not needed actually, since the call to getPreferredFormat
is nested in $form->isSubmitted() && $form->isValid()
, which means POST, which means no-cache.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More or less but:
- Turbo Streams can be used with GET requests too, this adds an example of how to handle content negotiation properly
- It's a best practice anyway to set Vary regardless of the verb
- Even if it's not commonly implemented by cache servers, responses to POST requests can be cached (by the spec) and reused for subsequent GET requests for the same resource
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but this example is about a form. The example you added in #217 has return $response->setVary('Accept');
, which is enough a hint to me.
Here, yes, POST can be cached, but ONLY if Cache-Control is sent. I think that if one does that (set the cc header), then it's their job to also add the Vary, and we don't have to tell everybody to add it.
This PR was squashed before being merged into the 2.x branch. Discussion ---------- [Turbo] Simplify stream negotiation | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes <!-- please update src/**/CHANGELOG.md files --> | Tickets | n/a | License | MIT This patch replaces the ad-hoc content negotiation system for Turbo Streams used by the bundle. HttpFoundation's native content negotiation features are now used instead. This greatly simplifies the code, which is security-sensitive, and improves DX (content negotiation is now consistent with how it is handled in the rest of the framework). Replaces #214. Needs #215 and symfony/symfony#44980. Commits ------- b6de1e3 [Turbo] Simplify stream negotiation
This PR was squashed before being merged into the 2.x branch. Discussion ---------- [Turbo] Simplify stream negotiation | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes <!-- please update src/**/CHANGELOG.md files --> | Tickets | n/a | License | MIT This patch replaces the ad-hoc content negotiation system for Turbo Streams used by the bundle. HttpFoundation's native content negotiation features are now used instead. This greatly simplifies the code, which is security-sensitive, and improves DX (content negotiation is now consistent with how it is handled in the rest of the framework). Replaces symfony/ux#214. Needs symfony/ux#215 and symfony/symfony#44980. Commits ------- b6de1e3 [Turbo] Simplify stream negotiation
This PR was squashed before being merged into the 2.x branch. Discussion ---------- [Turbo] Simplify stream negotiation | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes <!-- please update src/**/CHANGELOG.md files --> | Tickets | n/a | License | MIT This patch replaces the ad-hoc content negotiation system for Turbo Streams used by the bundle. HttpFoundation's native content negotiation features are now used instead. This greatly simplifies the code, which is security-sensitive, and improves DX (content negotiation is now consistent with how it is handled in the rest of the framework). Replaces symfony/ux#214. Needs symfony/ux#215 and symfony/symfony#44980. Commits ------- b6de1e3 [Turbo] Simplify stream negotiation
This PR was squashed before being merged into the 2.x branch. Discussion ---------- [Turbo] Simplify stream negotiation | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes <!-- please update src/**/CHANGELOG.md files --> | Tickets | n/a | License | MIT This patch replaces the ad-hoc content negotiation system for Turbo Streams used by the bundle. HttpFoundation's native content negotiation features are now used instead. This greatly simplifies the code, which is security-sensitive, and improves DX (content negotiation is now consistent with how it is handled in the rest of the framework). Replaces symfony/ux#214. Needs symfony/ux#215 and symfony/symfony#44980. Commits ------- b6de1e3 [Turbo] Simplify stream negotiation