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
Provenance
- Commit
b1bcaec- Tree
ae84323- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent
94e82e9
1 file changed+8 added−11 removed
modified:requests/sessions.py+8 added-11 removed
14 unmodified lines15 from .models import Request16 from .hooks import dispatch_hook17 from .utils import header_expand, from_key_val_list, default_headers18 from .packages.urllib3.poolmanager import PoolManager19+from .exceptions import TooManyRedirects20 21 from .compat import urlparse, urljoin22 from .adapters import HTTPAdapter23 37 unmodified lines61 62 return kwargs63 64 64-65 class SessionMixin(object):66 67 def resolve_redirects(self, resp, req, prefetch=True, timeout=None, verify=True, cert=None):68 """Receives a Response. Returns a generator of Responses."""69 70+ i = 071 72 # ((resp.status_code is codes.see_other))73 while (('location' in resp.headers and resp.status_code in REDIRECT_STATI)):74 75 resp.content # Consume socket so it can be released76 76- # if not len(history) < self.config.get('max_redirects'):77- # raise TooManyRedirects()77+ if i > self.max_redirects:78+ raise TooManyRedirects()79 80 # Release the connection back into the pool.81 resp.close()82 82- # history.append(r)83-83 url = resp.headers['location']84+ method = req.method85 86 # Handle redirection without scheme (see: RFC 1808 Section 4)87 if url.startswith('//'):88 parsed_rurl = urlparse(resp.url)1 unmodified line90 91 # 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))96 97 # 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.method100 101 # 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 lines125 cert=cert126 )127 128 yield resp129+ i += 1130 131 132 133 224 unmodified lines