1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +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

@@ -254,9 +254,13 @@ class URLVaryAcceptLanguageTests(URLTestCaseBase):
self.assertEqual(response.get('Vary'), 'Accept-Language')
def test_en_redirect(self):
"""
The redirect to a prefixed URL depends on 'Accept-Language' and
'Cookie', but once prefixed no header is set.
"""
response = self.client.get('/account/register/', HTTP_ACCEPT_LANGUAGE='en')
self.assertRedirects(response, '/en/account/register/')
self.assertFalse(response.get('Vary'))
self.assertEqual(response.get('Vary'), 'Accept-Language, Cookie')
response = self.client.get(response.headers['location'])
self.assertEqual(response.status_code, 200)