Skip to content
Myr

Fix the potential issue mentioned in #1151

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

See: https://github.com/kennethreitz/requests/pull/1151#issuecomment-12905796 This is solved by just reusing the PreparedRequest from the last request.

authored by Ian Cordasco · committed by Ian Cordasco · parent f2be5fa · Browse files · 1 file+18 added−17 removed
This commit

State

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

Diff stats

1 file+18 added−17 removed

  • other:+18 added−17 removed

1 file+18 added−17 removed

modified:requests/sessions.py+18 added-17 removed
72 unmodified lines
73 return kwargs747576class SessionRedirectMixin(object):7778 def resolve_redirects(self, resp, req, stream=False, timeout=None,79 verify=True, cert=None, proxies=None):77 def resolve_redirects(self, resp, prepared_request, stream=False,78 timeout=None, verify=True, cert=None, proxies=None):79 """Receives a Response. Returns a generator of Responses."""8081 i = 082
8 unmodified lines
91 # Release the connection back into the pool.92 resp.close()9394 url = resp.headers['location']96 method = req.method95 method = prepared_request.method9697 # Handle redirection without scheme (see: RFC 1808 Section 4)98 if url.startswith('//'):99 parsed_rurl = urlparse(resp.url)
4 unmodified lines
104 if not urlparse(url).netloc:105 # Compliant with RFC3986, we percent encode the url.106 url = urljoin(resp.url, requote_uri(url))107108 prepared_request.url = url109110 # http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.4110 if resp.status_code == codes.see_other and req.method != 'HEAD':111 if (resp.status_code == codes.see_other and112 prepared_request.method != 'HEAD'):113 method = 'GET'114115 # Do what the browsers do, despite standards...114 if resp.status_code in (codes.moved, codes.found) and req.method == 'POST':116 if (resp.status_code in (codes.moved, codes.found) and117 prepared_request.method == 'POST'):118 method = 'GET'119120 prepared_request.method = method121122 # Remove the cookie headers that were sent.118 headers = req.headers123 headers = prepared_request.headers124 try:125 del headers['Cookie']126 except KeyError:127 pass128124 resp = self.request(125 url=url,126 method=method,127 headers=headers,128 auth=req.auth,129 cookies=req.cookies,130 allow_redirects=False,129 resp = self.send(130 prepared_request,131 stream=stream,132 timeout=timeout,133 verify=verify,134 cert=cert,135 proxies=proxies,136 hooks=req.hooks,136 allow_redirects=False,137 )138139 i += 1140 yield resp
250 unmodified lines
391 # Total elapsed time of the request (approximately)392 r.elapsed = datetime.utcnow() - start393394 # Redirect resolving generator.395 gen = self.resolve_redirects(r, req, stream=stream, timeout=timeout,396 verify=verify, cert=cert, proxies=proxies)395 gen = self.resolve_redirects(r, request, stream=stream,396 timeout=timeout, verify=verify, cert=cert,397 proxies=proxies)398399 # Resolve redirects if allowed.400 history = [resp for resp in gen] if allow_redirects else []401
44 unmodified lines