Skip to content

[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

Closed
wants to merge 1 commit into from

Conversation

dunglas
Copy link
Member

@dunglas 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'])]
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More or less but:

  1. Turbo Streams can be used with GET requests too, this adds an example of how to handle content negotiation properly
  2. It's a best practice anyway to set Vary regardless of the verb
  3. 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

Copy link
Member

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.

chalasr added a commit that referenced this pull request Jan 12, 2022
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
symfony-splitter pushed a commit to symfony/ux-turbo that referenced this pull request Jan 12, 2022
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
@dunglas dunglas closed this Jan 12, 2022
marcuswebapp added a commit to marcuswebapp/ux that referenced this pull request Aug 1, 2023
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
symfony-splitter pushed a commit to symfony/ux-turbo that referenced this pull request Sep 22, 2023
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants