mirror of
https://github.com/django/django.git
synced 2025-11-14 09:17:36 +00:00
Fixed #23960 -- Removed http.fix_location_header
Thanks Carl Meyer for the report and Tim Graham for the review.
This commit is contained in:
parent
0339844b70
commit
a0c2eb46dd
20 changed files with 127 additions and 156 deletions
|
|
@ -23,7 +23,6 @@ logger = logging.getLogger('django.request')
|
|||
class BaseHandler(object):
|
||||
# Changes that are always applied to a response (in this order).
|
||||
response_fixes = [
|
||||
http.fix_location_header,
|
||||
http.conditional_content_removal,
|
||||
]
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ from django.http.response import (
|
|||
HttpResponseNotFound, HttpResponseNotAllowed, HttpResponseGone,
|
||||
HttpResponseServerError, Http404, BadHeaderError, JsonResponse,
|
||||
)
|
||||
from django.http.utils import fix_location_header, conditional_content_removal
|
||||
from django.http.utils import conditional_content_removal
|
||||
|
||||
__all__ = [
|
||||
'SimpleCookie', 'parse_cookie', 'HttpRequest', 'QueryDict',
|
||||
|
|
@ -17,6 +17,6 @@ __all__ = [
|
|||
'HttpResponsePermanentRedirect', 'HttpResponseNotModified',
|
||||
'HttpResponseBadRequest', 'HttpResponseForbidden', 'HttpResponseNotFound',
|
||||
'HttpResponseNotAllowed', 'HttpResponseGone', 'HttpResponseServerError',
|
||||
'Http404', 'BadHeaderError', 'fix_location_header', 'JsonResponse',
|
||||
'FileResponse', 'conditional_content_removal',
|
||||
'Http404', 'BadHeaderError', 'JsonResponse', 'FileResponse',
|
||||
'conditional_content_removal',
|
||||
]
|
||||
|
|
|
|||
|
|
@ -9,19 +9,6 @@ Functions that modify an HTTP request or response in some way.
|
|||
# universally applicable.
|
||||
|
||||
|
||||
def fix_location_header(request, response):
|
||||
"""
|
||||
Ensures that we always use an absolute URI in any location header in the
|
||||
response. This is required by RFC 2616, section 14.30.
|
||||
|
||||
Code constructing response objects is free to insert relative paths, as
|
||||
this function converts them to absolute paths.
|
||||
"""
|
||||
if 'Location' in response:
|
||||
response['Location'] = request.build_absolute_uri(response['Location'])
|
||||
return response
|
||||
|
||||
|
||||
def conditional_content_removal(request, response):
|
||||
"""
|
||||
Removes the content of responses for HEAD requests, 1xx, 204 and 304
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ class CommonMiddleware(object):
|
|||
if new_url == old_url:
|
||||
# No redirects required.
|
||||
return
|
||||
if new_url[0]:
|
||||
if new_url[0] != old_url[0]:
|
||||
newurl = "%s://%s%s" % (
|
||||
request.scheme,
|
||||
new_url[0], urlquote(new_url[1]))
|
||||
|
|
|
|||
|
|
@ -40,16 +40,12 @@ class LocaleMiddleware(object):
|
|||
|
||||
if path_valid:
|
||||
script_prefix = get_script_prefix()
|
||||
language_url = "%s://%s%s" % (
|
||||
request.scheme,
|
||||
request.get_host(),
|
||||
# insert language after the script prefix and before the
|
||||
# rest of the URL
|
||||
request.get_full_path().replace(
|
||||
script_prefix,
|
||||
'%s%s/' % (script_prefix, language),
|
||||
1
|
||||
)
|
||||
# Insert language after the script prefix and before the
|
||||
# rest of the URL
|
||||
language_url = request.get_full_path().replace(
|
||||
script_prefix,
|
||||
'%s%s/' % (script_prefix, language),
|
||||
1
|
||||
)
|
||||
return self.response_redirect_class(language_url)
|
||||
|
||||
|
|
|
|||
|
|
@ -37,7 +37,9 @@ from django.test.utils import (
|
|||
override_settings,
|
||||
)
|
||||
from django.utils import six
|
||||
from django.utils.deprecation import RemovedInDjango20Warning
|
||||
from django.utils.deprecation import (
|
||||
RemovedInDjango20Warning, RemovedInDjango21Warning,
|
||||
)
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.six.moves.urllib.parse import (
|
||||
unquote, urlparse, urlsplit, urlunsplit,
|
||||
|
|
@ -249,11 +251,15 @@ class SimpleTestCase(unittest.TestCase):
|
|||
TestClient to do a request (use fetch_redirect_response=False to check
|
||||
such links without fetching them).
|
||||
"""
|
||||
if host is not None:
|
||||
warnings.warn(
|
||||
"The host argument is deprecated and no longer used by assertRedirects",
|
||||
RemovedInDjango21Warning, stacklevel=2
|
||||
)
|
||||
|
||||
if msg_prefix:
|
||||
msg_prefix += ": "
|
||||
|
||||
e_scheme, e_netloc, e_path, e_query, e_fragment = urlsplit(expected_url)
|
||||
|
||||
if hasattr(response, 'redirect_chain'):
|
||||
# The request was a followed redirect
|
||||
self.assertTrue(len(response.redirect_chain) > 0,
|
||||
|
|
@ -295,10 +301,18 @@ class SimpleTestCase(unittest.TestCase):
|
|||
" response code was %d (expected %d)" %
|
||||
(path, redirect_response.status_code, target_status_code))
|
||||
|
||||
e_scheme = e_scheme if e_scheme else scheme or 'http'
|
||||
e_netloc = e_netloc if e_netloc else host or 'testserver'
|
||||
expected_url = urlunsplit((e_scheme, e_netloc, e_path, e_query,
|
||||
e_fragment))
|
||||
if url != expected_url:
|
||||
# For temporary backwards compatibility, try to compare with a relative url
|
||||
e_scheme, e_netloc, e_path, e_query, e_fragment = urlsplit(expected_url)
|
||||
relative_url = urlunsplit(('', '', e_path, e_query, e_fragment))
|
||||
if url == relative_url:
|
||||
warnings.warn(
|
||||
"assertRedirects had to strip the scheme and domain from the "
|
||||
"expected URL, as it was always added automatically to URLs "
|
||||
"before Django 1.9. Please update your expected URLs by "
|
||||
"removing the scheme and domain.",
|
||||
RemovedInDjango21Warning, stacklevel=2)
|
||||
expected_url = relative_url
|
||||
|
||||
self.assertEqual(url, expected_url,
|
||||
msg_prefix + "Response redirected to '%s', expected '%s'" %
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue