Skip to content
Myr

Don't reuse PreparedRequest on redirects

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Roman Haritonov · committed by Roman Haritonov · parent 798a1ff · Browse files · 2 files+7 added−10 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+7 added−10 removed

  • other:+7 added−10 removed

2 files+7 added−10 removed

modified:requests/sessions.py+7 added-9 removed
69 unmodified lines
70 verify=True, cert=None, proxies=None):71 """Receives a Response. Returns a generator of Responses."""7273 i = 074 prepared_request = PreparedRequest()75 prepared_request.body = req.body76 prepared_request.headers = req.headers.copy()77 prepared_request.hooks = req.hooks78 prepared_request.method = req.method79 prepared_request.url = req.url7475 # ((resp.status_code is codes.see_other))76 while (('location' in resp.headers and resp.status_code in REDIRECT_STATI)):77 prepared_request = PreparedRequest()78 prepared_request.body = req.body79 prepared_request.headers = req.headers.copy()80 prepared_request.hooks = req.hooks8182 resp.content # Consume socket so it can be released8384 if i >= self.max_redirects:
2 unmodified lines
87 # Release the connection back into the pool.88 resp.close()8990 url = resp.headers['location']93 method = prepared_request.method91 method = req.method9293 # Handle redirection without scheme (see: RFC 1808 Section 4)94 if url.startswith('//'):95 parsed_rurl = urlparse(resp.url)
15 unmodified lines
111 prepared_request.url = url112113 # http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.4114 if (resp.status_code == codes.see_other and117 prepared_request.method != 'HEAD'):115 method != 'HEAD'):116 method = 'GET'117118 # Do what the browsers do, despite standards...119 if (resp.status_code in (codes.moved, codes.found) and122 prepared_request.method not in ('GET', 'HEAD')):120 method not in ('GET', 'HEAD')):121 method = 'GET'122123 prepared_request.method = method124
380 unmodified lines
modified:test_requests.py-1 removed
167 unmodified lines
168 'foo=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT'169 }170 )171 assert 'foo' not in s.cookies172<<<<<<< HEAD172173 def test_request_cookie_overrides_session_cookie(self):174 s = requests.session()175 s.cookies['foo'] = 'bar'
573 unmodified lines