Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #3072 from collinanderson/23295

Fixed #23295 -- Removed unnecessary fix_location_header request.get_host() check
  • Loading branch information...
commit 9fef66ef7c3dbb156d0b235261ec499f81494eae 2 parents 90b64db + 230393e
@carljm carljm authored
Showing with 14 additions and 3 deletions.
  1. +1 −1  django/http/utils.py
  2. +13 −2 tests/http_utils/tests.py
View
2  django/http/utils.py
@@ -17,7 +17,7 @@ def fix_location_header(request, response):
Code constructing response objects is free to insert relative paths, as
this function converts them to absolute paths.
"""
- if 'Location' in response and request.get_host():
+ if 'Location' in response:
response['Location'] = request.build_absolute_uri(response['Location'])
return response
View
15 tests/http_utils/tests.py
@@ -3,8 +3,8 @@
import io
import gzip
-from django.http import HttpRequest, HttpResponse, StreamingHttpResponse
-from django.http.utils import conditional_content_removal
+from django.http import HttpRequest, HttpResponse, HttpResponseRedirect, StreamingHttpResponse
+from django.http.utils import conditional_content_removal, fix_location_header
from django.test import TestCase
@@ -69,3 +69,14 @@ def test_conditional_content_removal(self):
res = StreamingHttpResponse(['abc'])
conditional_content_removal(req, res)
self.assertEqual(b''.join(res), b'')
+
+ def test_fix_location_without_get_host(self):
+ """
+ Tests that you can return an absolute redirect when the request
+ host is not in ALLOWED_HOSTS. Issue #20472
+ """
+ request = HttpRequest()
+ def bomb():
+ self.assertTrue(False)
+ request.get_host = bomb
+ fix_location_header(request, HttpResponseRedirect('http://example.com'))
Please sign in to comment.
Something went wrong with that request. Please try again.