summaryrefslogtreecommitdiff
path: root/django/test/client.py
diff options
context:
space:
mode:
authorAhmad A. Hussein <ahmadahussein0@gmail.com>2020-05-27 08:10:08 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-05-27 10:36:52 +0200
commit7c947f0f5a0539add9adf8c4e14726ea509e13ef (patch)
tree90974bb4b3de86fa3d46769a87e55b7bc068ed98 /django/test/client.py
parent6425fd3124e50219ba0b6f545d1bf7edfb053a59 (diff)
Fixed #31494 -- Preserved query strings when following HTTP 307/308 redirects in test client.
Diffstat (limited to 'django/test/client.py')
-rw-r--r--django/test/client.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/django/test/client.py b/django/test/client.py
index b26504f762..ce74a5fe53 100644
--- a/django/test/client.py
+++ b/django/test/client.py
@@ -826,8 +826,12 @@ class Client(ClientMixin, RequestFactory):
path = urljoin(response.request['PATH_INFO'], path)
if response.status_code in (HTTPStatus.TEMPORARY_REDIRECT, HTTPStatus.PERMANENT_REDIRECT):
- # Preserve request method post-redirect for 307/308 responses.
- request_method = getattr(self, response.request['REQUEST_METHOD'].lower())
+ # Preserve request method and query string (if needed)
+ # post-redirect for 307/308 responses.
+ request_method = response.request['REQUEST_METHOD'].lower()
+ if request_method not in ('get', 'head'):
+ extra['QUERY_STRING'] = url.query
+ request_method = getattr(self, request_method)
else:
request_method = self.get
data = QueryDict(url.query)