Skip to content
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

Vary Accept-Language being added #4

Closed
oppianmatt opened this issue May 12, 2014 · 3 comments
Closed

Vary Accept-Language being added #4

oppianmatt opened this issue May 12, 2014 · 3 comments

Comments

@oppianmatt
Copy link

It would seem the point of using language urls is that you don't vary accept-languages. But if you request the default language that doesn't have a url prefix it adds the vary accept-language.

The method is:

def process_response(self, request, response):
    language = trans.get_language()
    kwargs = {}
    if self.use_redirects:
        rr_response = super(SolidLocaleMiddleware, self).\
            process_response(request, response)
        if rr_response and not(
                isinstance(rr_response, HttpResponseRedirect)
                and language == self.default_lang):
            return rr_response

    if django_root_version >= 16:
        kwargs["supported"] = self._supported_languages
    language_from_path = translation.get_language_from_path(
        request.path_info, **kwargs)
    if not (self.is_language_prefix_patterns_used()
            and language_from_path):
        patch_vary_headers(response, ('Accept-Language',))
    if 'Content-Language' not in response:
        response['Content-Language'] = language
    return response

Probably should put vary Accept-Language before the redirect (otherwise the redirect can be cached). Basically if the response is different based on the language, we need the header, if it isn't we don't. Here the redirect is different based on the request languages. But when we deliver normal page content, the pages content is not different based on language so we dont want accept-language (which will make it cache less).

@st4lk
Copy link
Owner

st4lk commented May 13, 2014

Hi Matthew, thanks for reporting!

So the behaviour must be the following:

if settings.SOLID_I18N_USE_REDIRECTS == False, then Vary Accept-Language header must never be set. Because in that case url without prefix will always return content in default language and url with prefix will always return content in language from that prefix. No redirects will occur.

if settings.SOLID_I18N_USE_REDIRECTS == True, then Vary Accept-Language header must always be set for url without prefix, because from that url the redirect can occur (if request's language is not equal to default language). And for url with prefix Vary Accept-Language must never be set, because such url behaves the same as previous case, i.e. always render content with language from prefix.

Am i right?

@oppianmatt
Copy link
Author

Yep that's right. Thanks.

@st4lk
Copy link
Owner

st4lk commented May 25, 2014

Uploaded to pypi v0.4.3

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

No branches or pull requests

2 participants