1
0
mirror of https://github.com/django/django.git synced 2025-10-24 14:16:09 +00:00

Fixed #32768 -- Added Vary header when redirecting to prefixed i18n pattern.

get_language_from_request() uses Accept-Language and/or Cookie to determine the
correct redirect. Upstream caches need the matching Vary header to cache the
result.
This commit is contained in:
Alex Hayward
2021-05-19 12:19:23 +01:00
committed by Carlton Gibson
parent 84c7c4a477
commit eeed488a34
2 changed files with 11 additions and 2 deletions

View File

@@ -53,7 +53,12 @@ class LocaleMiddleware(MiddlewareMixin):
'%s%s/' % (script_prefix, language),
1
)
return self.response_redirect_class(language_url)
# Redirect to the language-specific URL as detected by
# get_language_from_request(). HTTP caches may cache this
# redirect, so add the Vary header.
redirect = self.response_redirect_class(language_url)
patch_vary_headers(redirect, ('Accept-Language', 'Cookie'))
return redirect
if not (i18n_patterns_used and language_from_path):
patch_vary_headers(response, ('Accept-Language',))