Skip to content
Myr

MaxRedirects

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

authored by Kenneth Reitz · committed by Kenneth Reitz · parent 94e82e9 · Browse files · 1 file+8 added−11 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+8 added−11 removed

  • other:+8 added−11 removed

1 file+8 added−11 removed

modified:requests/sessions.py+8 added-11 removed
14 unmodified lines
15from .models import Request16from .hooks import dispatch_hook17from .utils import header_expand, from_key_val_list, default_headers18from .packages.urllib3.poolmanager import PoolManager19from .exceptions import TooManyRedirects2021from .compat import urlparse, urljoin22from .adapters import HTTPAdapter23
37 unmodified lines
6162 return kwargs63646465class SessionMixin(object):6667 def resolve_redirects(self, resp, req, prefetch=True, timeout=None, verify=True, cert=None):68 """Receives a Response. Returns a generator of Responses."""6970 i = 07172 # ((resp.status_code is codes.see_other))73 while (('location' in resp.headers and resp.status_code in REDIRECT_STATI)):7475 resp.content # Consume socket so it can be released7676 # if not len(history) < self.config.get('max_redirects'):77 # raise TooManyRedirects()77 if i > self.max_redirects:78 raise TooManyRedirects()7980 # Release the connection back into the pool.81 resp.close()8282 # history.append(r)8383 url = resp.headers['location']84 method = req.method8586 # Handle redirection without scheme (see: RFC 1808 Section 4)87 if url.startswith('//'):88 parsed_rurl = urlparse(resp.url)
1 unmodified line
9091 # Facilitate non-RFC2616-compliant 'location' headers92 # (e.g. '/path/to/resource' instead of 'http://domain.tld/path/to/resource')93 if not urlparse(url).netloc:94 url = urljoin(resp.url,95 # Compliant with RFC3986, we percent96 # encode the url.97 requote_uri(url))94 # Compliant with RFC3986, we percent encode the url.95 url = urljoin(resp.url, requote_uri(url))9697 # http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.498 if resp.status_code is codes.see_other:99 method = 'GET'102 else:103 method = req.method100101 # Do what the browsers do, despite standards...102 if resp.status_code in (codes.moved, codes.found) and req.method == 'POST':103 method = 'GET'
21 unmodified lines
125 cert=cert126 )127128 yield resp129 i += 1130131132133
224 unmodified lines