Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[HttpFoundation] add a default Content-Language to the Response#36507
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
[HttpFoundation] add a default Content-Language to the Response#36507
Uh oh!
There was an error while loading.Please reload this page.
Conversation
nicolas-grekas left a comment
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.
some quick comments
| ->scalarNode('ide')->defaultNull()->end() | ||
| ->booleanNode('test')->end() | ||
| ->scalarNode('default_locale')->defaultValue('en')->end() | ||
| ->arrayNode('available_locales') |
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.
there isenabled_locales already, can't we reuse it?
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.
it's in the translator section.
what if the translator is not available?
Is it still relevant to reuse it?
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.
My fear is that it will be confusing for users to have to configure this twice.
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.
I suggest to make the translator option defaulting to the value of this new parameter if not set explicitly (and to not set it explicitly in the recipe). It’s already what we do for the default local IIRC.
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.
or we could move the setting out of the translation subtree.
again, having twice the same setting is calling for troubles to me.
src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/HttpKernel/EventListener/LocaleListener.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
nicolas-grekas commentedApr 21, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
What's the purpose of this feature? HTTP negotiation is tricky, as explained on the doc of Varnish and on Cloudflare (whichactively works against HTTP negotiation btw). Most apps do localization by embedding the locale into URLs. This removes all issues with HTTP negotiation. Thus the challenge I'm posting here: why? :) |
GregoireHebert commentedApr 21, 2020
Hello@nicolas-grekas :)
We can agree that, as defined inRFC 2616 the content language(s) should be expressed by the Content-Language Header. Which is not the case at the moment in Symfony. It could be one or multiple languages, but let stick to a default behaviour where our content is only made of one language. Thus as corollary, we should be able to serve the data according to the Having this managed by default allows us to stick closer to the HTTP behaviour, It does not override the URL locale behaviour, which is still the best solution when using cloudflare.
I applied@dunglas solution for now but find it "hacky". |
nicolas-grekas commentedApr 21, 2020
Instead of copying the request on the response, which might be just wrong, what about using the locale - the one that the locale-aware services manage? |
GregoireHebert commentedApr 22, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I am not sure to follow your train of thought. I'll check but I have the feeling that Oh ok, Let' say this: Now I create a Was that an intended behaviour or is it missing a check upon wether it's a master request or not? I feel like this should expect to be frhttps://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpKernel/Tests/EventListener/LocaleAwareListenerTest.php#L56 And anyway, it's a copy from the request, of course, we should be able to serve the result the closest what has been asked. Something else to do maybe, could be to keep track of every langage used by the translator, (in addition to the classic behaviour of, "I want a language and you shall give me the most approaching result") and if it differs from what's expected, then setup the different languages used by the translator. (but in another translator related listener I suppose, and in another PR ^^). WDYT? |
nicolas-grekas commentedApr 22, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
My thought is that HTTP negotiation is risky, look eg atthis patch, which fixes a CVE. I'm not sure we should default to using HTTP negotiation at all. The URL is a much better way to select the locale, both internally (the app) and for clients (browsers). |
GregoireHebert commentedApr 22, 2020
Alright, I let go this PR... It's a pity. @dunglas I think we should follow the same recommendation for API-Platform then. |
fabpot commentedJun 24, 2020
What's the status of this PR?@nicolas-grekas? |
nicolas-grekas commentedJun 24, 2020
My reasoning here is that this adds complexity, has risks (cache poisoning) and very specific benefits. |
nicolas-grekas commentedJun 24, 2020
Closing meanwhile. |
GregoireHebert commentedAug 28, 2020
Hello@nicolas-grekas :) I'd like to challenge you (and the community of course) again on this one :p This is not really a discouraged usage of HTTP. When I look at the documentation you sent, it's more of a cache sharding behaviour that is to be expected. Not a cache poisoning. I saw your accept-content revert commit, and it's not the same thing at all, it is against the specification itself, while accept-language is not. Anyway in terms of risk of DDOS attack the fact that one could theorically ping every language authorized possible does not change regardless the way of doing it. URL nor Header. All that being said, I don't see this as much as a risk for 2 reasons. It's part of the HTTP specification, and it's opt-in. Moreover, since the browsers are already set with one's prefered languages it's a win-win for everyone in my opinion. |
ogizanagi commentedJul 4, 2021 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Hi@GregoireHebert 👋🏻 This subject came back in the core team recently. Since this is opt-in and already targets to restrict the locales forwarded from the request to the response, we're open to re-discuss it. Would you be up to work back on this? |
GregoireHebert commentedJul 4, 2021
Yup sure, with pleasure! |
…n (GregoireHebert)This PR was merged into the 5.4 branch.Discussion----------[HttpKernel] Add basic support for language negotiation| Q | A| ------------- | ---| Branch? | 5.4| Bug fix? | no| New feature? | yes| Deprecations? | no| Tickets | -| License | MIT| Doc PR | -Continuation of#36507. Thanks `@GregoireHebert`!This PR adds two options to the framework configuration:- `set_locale_from_accept_language`: Makes the `Request`' locale automatically set based on the `Accept-Language` header (restricted by a new `framework.enabled_locales` config option which replaces `framework.translator.enabled_locales`).The explicit `_locale` request attribute always wins over the `Accept-Language` header when it's set.- `set_content_language_from_locale`: Sets the `Content-Language` Response header based on the `Request`' locale.This is going to be useful for API Platform and related (e.g.Sylius/Sylius#11412).Commits-------904b54f [HttpKernel] Add basic support for language negotiation
Uh oh!
There was an error while loading.Please reload this page.
This PR will allow to add a default Content-Language header in the Response.
It also add a new
available_localesentry under the framework configuration.If this array is not empty, it will try to set the request locale according to the preferredLanguage (Accept-Language header), only if there isn't any
_localeattribute.Todo