summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2011-11-27 20:04:13 +0000
committerAymeric Augustin <aymeric.augustin@m4x.org>2011-11-27 20:04:13 +0000
commit33a52cde08ef7ab8ba8990d40646d0dc2a8482df (patch)
tree543765fcd4c45f738ef94e9bc04b831e3afcf640 /django
parentc11f9c3193901215ec79732af6ab6c66b3c1c2ba (diff)
Fixed #16040 -- Preserved scheme, host and port in the test client when following a redirect.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17157 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
-rw-r--r--django/test/client.py17
1 files changed, 8 insertions, 9 deletions
diff --git a/django/test/client.py b/django/test/client.py
index 30ef746f6c..94fabcf91a 100644
--- a/django/test/client.py
+++ b/django/test/client.py
@@ -546,19 +546,18 @@ class Client(RequestFactory):
response.redirect_chain = []
while response.status_code in (301, 302, 303, 307):
url = response['Location']
- scheme, netloc, path, query, fragment = urlsplit(url)
-
redirect_chain = response.redirect_chain
redirect_chain.append((url, response.status_code))
- if scheme:
- extra['wsgi.url_scheme'] = scheme
+ url = urlsplit(url)
+ if url.scheme:
+ extra['wsgi.url_scheme'] = url.scheme
+ if url.hostname:
+ extra['SERVER_NAME'] = url.hostname
+ if url.port:
+ extra['SERVER_PORT'] = str(url.port)
- # The test client doesn't handle external links,
- # but since the situation is simulated in test_client,
- # we fake things here by ignoring the netloc portion of the
- # redirected URL.
- response = self.get(path, QueryDict(query), follow=False, **extra)
+ response = self.get(url.path, QueryDict(url.query), follow=False, **extra)
response.redirect_chain = redirect_chain
# Prevent loops