Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #17817 -- Modified LocalMiddleware to use full URLs when redire…

…cting to i18n URLs. Thanks to Paul for keeping an eye on the standards.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17633 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 126d9e1b499663e72cc795906bdbcd333aceaf0a 1 parent b9bf7cc
Jannis Leidel authored March 02, 2012
7  django/middleware/locale.py
@@ -33,9 +33,12 @@ def process_response(self, request, response):
33 33
             language_path = '/%s%s' % (language, request.path_info)
34 34
             if settings.APPEND_SLASH and not language_path.endswith('/'):
35 35
                 language_path = language_path + '/'
  36
+
36 37
             if is_valid_path(language_path, urlconf):
37  
-                return HttpResponseRedirect(
38  
-                    '/%s%s' % (language, request.get_full_path()))
  38
+                language_url = "%s://%s/%s%s" % (
  39
+                    request.is_secure() and 'https' or 'http',
  40
+                    request.get_host(), language, request.get_full_path())
  41
+                return HttpResponseRedirect(language_url)
39 42
         translation.deactivate()
40 43
 
41 44
         patch_vary_headers(response, ('Accept-Language',))
8  tests/regressiontests/i18n/patterns/tests.py
@@ -182,12 +182,10 @@ def test_not_prefixed_redirect(self):
182 182
         self.assertRedirects(response, '/not-prefixed/', 301)
183 183
 
184 184
     def test_en_redirect(self):
185  
-        response = self.client.get('/account/register', HTTP_ACCEPT_LANGUAGE='en')
  185
+        response = self.client.get('/account/register', HTTP_ACCEPT_LANGUAGE='en', follow=True)
186 186
         # target status code of 301 because of CommonMiddleware redirecting
187  
-        self.assertRedirects(response, '/en/account/register', 302, target_status_code=301)
188  
-
189  
-        response = self.client.get(response['location'])
190  
-        self.assertRedirects(response, '/en/account/register/', 301)
  187
+        self.assertIn(('http://testserver/en/account/register/', 301), response.redirect_chain)
  188
+        self.assertRedirects(response, '/en/account/register/', 302)
191 189
 
192 190
 
193 191
 class URLRedirectWithoutTrailingSlashSettingTests(URLTestCaseBase):

0 notes on commit 126d9e1

Please sign in to comment.
Something went wrong with that request. Please try again.