From 798a1ffdec682fe8b9e0c3386f445ab6e1fd801c Mon Sep 17 00:00:00 2001 From: Roman Haritonov Date: Fri, 19 Apr 2013 10:12:34 +0400 Subject: [PATCH 1/2] new failing test_requests_in_history_are_not_overridden() --- test_requests.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test_requests.py b/test_requests.py index d0d8d9e6..fed70d8d 100755 --- a/test_requests.py +++ b/test_requests.py @@ -169,6 +169,7 @@ class RequestsTestCase(unittest.TestCase): } ) assert 'foo' not in s.cookies +<<<<<<< HEAD def test_request_cookie_overrides_session_cookie(self): s = requests.session() @@ -188,7 +189,13 @@ class RequestsTestCase(unittest.TestCase): assert r.json()['cookies']['foo'] == 'bar' # Make sure the session cj is still the custom one assert s.cookies is cj - + + def test_requests_in_history_are_not_overridden(self): + resp = requests.get(httpbin('redirect/3')) + urls = [r.url for r in resp.history] + req_urls = [r.request.url for r in resp.history] + self.assertEquals(urls, req_urls) + def test_user_agent_transfers(self): heads = { From 716b627c1e7c86af722affe973a11df4d5812a1b Mon Sep 17 00:00:00 2001 From: Roman Haritonov Date: Fri, 19 Apr 2013 10:13:36 +0400 Subject: [PATCH 2/2] Don't reuse PreparedRequest on redirects --- requests/sessions.py | 16 +++++++--------- test_requests.py | 1 - 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/requests/sessions.py b/requests/sessions.py index 634637f4..6d1000dc 100644 --- a/requests/sessions.py +++ b/requests/sessions.py @@ -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 diff --git a/test_requests.py b/test_requests.py index fed70d8d..7ad10ee9 100755 --- a/test_requests.py +++ b/test_requests.py @@ -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()