diff --git a/django/core/handlers/base.py b/django/core/handlers/base.py
index eba7811..7dc2580 100644
a
|
b
|
logger = logging.getLogger('django.request')
|
22 | 22 | class BaseHandler(object): |
23 | 23 | # Changes that are always applied to a response (in this order). |
24 | 24 | response_fixes = [ |
25 | | http.fix_location_header, |
26 | 25 | http.conditional_content_removal, |
27 | 26 | ] |
28 | 27 | |
diff --git a/django/http/__init__.py b/django/http/__init__.py
index fc5bd18..2a089a4 100644
a
|
b
|
from django.http.response import (HttpResponse, StreamingHttpResponse,
|
6 | 6 | HttpResponseNotModified, HttpResponseBadRequest, HttpResponseForbidden, |
7 | 7 | HttpResponseNotFound, HttpResponseNotAllowed, HttpResponseGone, |
8 | 8 | HttpResponseServerError, Http404, BadHeaderError, JsonResponse) |
9 | | from django.http.utils import fix_location_header, conditional_content_removal |
| 9 | from django.http.utils import conditional_content_removal |
10 | 10 | |
11 | 11 | __all__ = [ |
12 | 12 | 'SimpleCookie', 'parse_cookie', 'HttpRequest', 'QueryDict', |
… |
… |
__all__ = [
|
15 | 15 | 'HttpResponsePermanentRedirect', 'HttpResponseNotModified', |
16 | 16 | 'HttpResponseBadRequest', 'HttpResponseForbidden', 'HttpResponseNotFound', |
17 | 17 | 'HttpResponseNotAllowed', 'HttpResponseGone', 'HttpResponseServerError', |
18 | | 'Http404', 'BadHeaderError', 'fix_location_header', 'JsonResponse', |
19 | | 'conditional_content_removal', |
| 18 | 'Http404', 'BadHeaderError', 'JsonResponse', 'conditional_content_removal', |
20 | 19 | ] |
diff --git a/django/http/utils.py b/django/http/utils.py
index 5dcac06..3ea71cb 100644
a
|
b
|
Functions that modify an HTTP request or response in some way.
|
9 | 9 | # universally applicable. |
10 | 10 | |
11 | 11 | |
12 | | def fix_location_header(request, response): |
13 | | """ |
14 | | Ensures that we always use an absolute URI in any location header in the |
15 | | response. This is required by RFC 2616, section 14.30. |
16 | | |
17 | | Code constructing response objects is free to insert relative paths, as |
18 | | this function converts them to absolute paths. |
19 | | """ |
20 | | if 'Location' in response: |
21 | | response['Location'] = request.build_absolute_uri(response['Location']) |
22 | | return response |
23 | | |
24 | | |
25 | 12 | def conditional_content_removal(request, response): |
26 | 13 | """ |
27 | 14 | Removes the content of responses for HEAD requests, 1xx, 204 and 304 |
diff --git a/docs/releases/1.8.txt b/docs/releases/1.8.txt
index 375a399..a6ac833 100644
a
|
b
|
Miscellaneous
|
853 | 853 | :exc:`~django.test.client.RedirectCycleError` if it detects a loop or hits a |
854 | 854 | maximum redirect limit (rather than passing silently). |
855 | 855 | |
| 856 | * Relative redirects are no longer converted to absolute URIs. :rfc:`2616` |
| 857 | required the ``Location`` header in redirect responses to be an absolute URI, |
| 858 | but it has been superseded by :rfc:`7231` which allows relative URIs in |
| 859 | ``Location``, recognizing the actual practice of user agents, almost all of |
| 860 | which support them. |
| 861 | |
856 | 862 | .. _deprecated-features-1.8: |
857 | 863 | |
858 | 864 | Features deprecated in 1.8 |
diff --git a/tests/http_utils/tests.py b/tests/http_utils/tests.py
index d88afb9..86364ef 100644
a
|
b
|
import io
|
4 | 4 | import gzip |
5 | 5 | |
6 | 6 | from django.http import HttpRequest, HttpResponse, HttpResponseRedirect, StreamingHttpResponse |
7 | | from django.http.utils import conditional_content_removal, fix_location_header |
| 7 | from django.http.utils import conditional_content_removal |
8 | 8 | from django.test import TestCase |
9 | 9 | |
10 | 10 | |
… |
… |
class HttpUtilTests(TestCase):
|
69 | 69 | res = StreamingHttpResponse(['abc']) |
70 | 70 | conditional_content_removal(req, res) |
71 | 71 | self.assertEqual(b''.join(res), b'') |
72 | | |
73 | | def test_fix_location_without_get_host(self): |
74 | | """ |
75 | | Tests that you can return an absolute redirect when the request |
76 | | host is not in ALLOWED_HOSTS. Issue #20472 |
77 | | """ |
78 | | request = HttpRequest() |
79 | | |
80 | | def bomb(): |
81 | | self.assertTrue(False) |
82 | | request.get_host = bomb |
83 | | fix_location_header(request, HttpResponseRedirect('http://example.com')) |