Ticket #17092: add_host_to_location.2.diff
File add_host_to_location.2.diff, 4.1 KB (added by , 13 years ago) |
---|
-
django/http/__init__.py
535 535 status_code = 200 536 536 537 537 def __init__(self, content='', mimetype=None, status=None, 538 content_type=None ):538 content_type=None, add_host_to_location=True): 539 539 # _headers is a mapping of the lower-case name to the original case of 540 540 # the header (required for working with legacy systems) and the header 541 541 # value. Both the name of the header and its value are ASCII strings. … … 552 552 self.status_code = status 553 553 554 554 self['Content-Type'] = content_type 555 self.add_host_to_location = add_host_to_location 555 556 556 557 def __str__(self): 557 558 """Full HTTP message, including headers.""" -
django/http/utils.py
16 16 Code constructing response objects is free to insert relative paths, as 17 17 this function converts them to absolute paths. 18 18 """ 19 if 'Location' in response and request.get_host(): 19 if 'Location' in response and response.add_host_to_location \ 20 and request.get_host(): 20 21 response['Location'] = request.build_absolute_uri(response['Location']) 21 22 return response 22 23 -
docs/ref/request-response.txt
597 597 Methods 598 598 ------- 599 599 600 .. method:: HttpResponse.__init__(content='', mimetype=None, status=200, content_type=DEFAULT_CONTENT_TYPE )600 .. method:: HttpResponse.__init__(content='', mimetype=None, status=200, content_type=DEFAULT_CONTENT_TYPE, add_host_to_location=True) 601 601 602 602 Instantiates an ``HttpResponse`` object with the given page content (a 603 603 string) and MIME type. The :setting:`DEFAULT_CONTENT_TYPE` is … … 619 619 Otherwise, ``content_type`` is used. If neither is given, the 620 620 :setting:`DEFAULT_CONTENT_TYPE` setting is used. 621 621 622 .. versionadded:: 1.4 623 624 ``add_host_to_location`` by default django ensures that all location 625 headers contain an absolute URI using request.build_absolute_uri if you 626 need to disable this behavior set ``add_host_to_location`` to False. 627 622 628 .. method:: HttpResponse.__setitem__(header, value) 623 629 624 630 Sets the given header name to the given value. Both ``header`` and -
tests/regressiontests/requests/tests.py
6 6 from django.core.handlers.modpython import ModPythonRequest 7 7 from django.core.handlers.wsgi import WSGIRequest, LimitedStream 8 8 from django.http import HttpRequest, HttpResponse, parse_cookie, build_request_repr 9 from django.http.utils import fix_location_header 9 10 from django.utils import unittest 10 11 from django.utils.http import cookie_date 11 12 13 class FixHeaderTests(unittest.TestCase): 14 def test_httprequest_add_host(self): 15 request = HttpRequest() 16 request.META = { 17 u'HTTP_HOST': u'example.com', 18 } 19 response = HttpResponse() 20 response['Location'] = '/test' 21 response = fix_location_header(request, response) 22 self.assertEqual(response['Location'], 'http://example.com/test') 12 23 24 def test_httprequest_no_host(self): 25 request = HttpRequest() 26 response = HttpResponse(add_host_to_location=False) 27 response['Location'] = '/test' 28 response = fix_location_header(request, response) 29 self.assertEqual(response['Location'], '/test') 30 13 31 class RequestsTests(unittest.TestCase): 14 32 def test_httprequest(self): 33 print 'hi' 15 34 request = HttpRequest() 16 35 self.assertEqual(request.GET.keys(), []) 17 36 self.assertEqual(request.POST.keys(), [])