Ticket #23960: 23960.diff

File 23960.diff, 4.1 KB (added by Tim Graham, 10 years ago)
  • django/core/handlers/base.py

    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')  
    2222class BaseHandler(object):
    2323    # Changes that are always applied to a response (in this order).
    2424    response_fixes = [
    25         http.fix_location_header,
    2625        http.conditional_content_removal,
    2726    ]
    2827
  • django/http/__init__.py

    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,  
    66    HttpResponseNotModified, HttpResponseBadRequest, HttpResponseForbidden,
    77    HttpResponseNotFound, HttpResponseNotAllowed, HttpResponseGone,
    88    HttpResponseServerError, Http404, BadHeaderError, JsonResponse)
    9 from django.http.utils import fix_location_header, conditional_content_removal
     9from django.http.utils import conditional_content_removal
    1010
    1111__all__ = [
    1212    'SimpleCookie', 'parse_cookie', 'HttpRequest', 'QueryDict',
    __all__ = [  
    1515    'HttpResponsePermanentRedirect', 'HttpResponseNotModified',
    1616    'HttpResponseBadRequest', 'HttpResponseForbidden', 'HttpResponseNotFound',
    1717    'HttpResponseNotAllowed', 'HttpResponseGone', 'HttpResponseServerError',
    18     'Http404', 'BadHeaderError', 'fix_location_header', 'JsonResponse',
    19     'conditional_content_removal',
     18    'Http404', 'BadHeaderError', 'JsonResponse', 'conditional_content_removal',
    2019]
  • django/http/utils.py

    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.  
    99# universally applicable.
    1010
    1111
    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 
    2512def conditional_content_removal(request, response):
    2613    """
    2714    Removes the content of responses for HEAD requests, 1xx, 204 and 304
  • docs/releases/1.8.txt

    diff --git a/docs/releases/1.8.txt b/docs/releases/1.8.txt
    index 375a399..a6ac833 100644
    a b Miscellaneous  
    853853  :exc:`~django.test.client.RedirectCycleError` if it detects a loop or hits a
    854854  maximum redirect limit (rather than passing silently).
    855855
     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
    856862.. _deprecated-features-1.8:
    857863
    858864Features deprecated in 1.8
  • tests/http_utils/tests.py

    diff --git a/tests/http_utils/tests.py b/tests/http_utils/tests.py
    index d88afb9..86364ef 100644
    a b import io  
    44import gzip
    55
    66from django.http import HttpRequest, HttpResponse, HttpResponseRedirect, StreamingHttpResponse
    7 from django.http.utils import conditional_content_removal, fix_location_header
     7from django.http.utils import conditional_content_removal
    88from django.test import TestCase
    99
    1010
    class HttpUtilTests(TestCase):  
    6969        res = StreamingHttpResponse(['abc'])
    7070        conditional_content_removal(req, res)
    7171        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'))
Back to Top