st4lk / django-solid-i18n-urls

[DEPRECATED] Use default language for urls without language prefix.
http://www.lexev.org/en/
Other
112 stars 29 forks source link

Vary Accept-Language being added #4

Closed oppianmatt closed 10 years ago

oppianmatt commented 10 years ago

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 commented 10 years ago

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 commented 10 years ago

Yep that's right. Thanks.

st4lk commented 10 years ago

Uploaded to pypi v0.4.3