Don't reuse PreparedRequest on redirects

This commit is contained in:
Roman Haritonov
2013-04-19 10:13:36 +04:00
parent 798a1ffdec
commit 716b627c1e
2 changed files with 7 additions and 10 deletions
+7 -9
View File
@@ -71,15 +71,13 @@ class SessionRedirectMixin(object):
"""Receives a Response. Returns a generator of Responses."""
i = 0
prepared_request = PreparedRequest()
prepared_request.body = req.body
prepared_request.headers = req.headers.copy()
prepared_request.hooks = req.hooks
prepared_request.method = req.method
prepared_request.url = req.url
# ((resp.status_code is codes.see_other))
while (('location' in resp.headers and resp.status_code in REDIRECT_STATI)):
prepared_request = PreparedRequest()
prepared_request.body = req.body
prepared_request.headers = req.headers.copy()
prepared_request.hooks = req.hooks
resp.content # Consume socket so it can be released
@@ -90,7 +88,7 @@ class SessionRedirectMixin(object):
resp.close()
url = resp.headers['location']
method = prepared_request.method
method = req.method
# Handle redirection without scheme (see: RFC 1808 Section 4)
if url.startswith('//'):
@@ -114,12 +112,12 @@ class SessionRedirectMixin(object):
# http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.4
if (resp.status_code == codes.see_other and
prepared_request.method != 'HEAD'):
method != 'HEAD'):
method = 'GET'
# Do what the browsers do, despite standards...
if (resp.status_code in (codes.moved, codes.found) and
prepared_request.method not in ('GET', 'HEAD')):
method not in ('GET', 'HEAD')):
method = 'GET'
prepared_request.method = method
-1
View File
@@ -169,7 +169,6 @@ class RequestsTestCase(unittest.TestCase):
}
)
assert 'foo' not in s.cookies
<<<<<<< HEAD
def test_request_cookie_overrides_session_cookie(self):
s = requests.session()