Skip to content
Myr

Merge pull request #2095 from ericfrederich/redirect_cache

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

Redirect cache

authored by Kenneth Reitz · committed by Kenneth Reitz · parents 2c262de, 493697a · Browse files · 2 files+14 added−1 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+14 added−1 removed

  • other:+14 added−1 removed

2 files+14 added−1 removed

modified:requests/models.py+5 added
609 unmodified lines
610 """611 return ('location' in self.headers and self.status_code in REDIRECT_STATI)612613 @property614 def is_permanent_redirect(self):615 """True if this Response one of the permanant versions of redirect"""616 return ('location' in self.headers and self.status_code in (codes.moved_permanently, codes.permanent_redirect))617618 @property619 def apparent_encoding(self):620 """The apparent encoding, provided by the chardet library"""621 return chardet.detect(self.content)['encoding']622
191 unmodified lines
modified:requests/sessions.py+9 added-1 removed
125 unmodified lines
126 else:127 url = requote_uri(url)128129 prepared_request.url = to_native_string(url)130 # cache the url131 if resp.is_permanent_redirect:132 self.redirect_cache[req.url] = prepared_request.url133134 # http://tools.ietf.org/html/rfc7231#section-6.4.4135 if (resp.status_code == codes.see_other and136 method != 'HEAD'):
128 unmodified lines
265266 __attrs__ = [267 'headers', 'cookies', 'auth', 'timeout', 'proxies', 'hooks',268 'params', 'verify', 'cert', 'prefetch', 'adapters', 'stream',266 'trust_env', 'max_redirects']269 'trust_env', 'max_redirects', 'redirect_cache']270271 def __init__(self):272273 #: A case-insensitive dictionary of headers to be sent on each
44 unmodified lines
318 self.adapters = OrderedDict()319 self.mount('https://', HTTPAdapter())320 self.mount('http://', HTTPAdapter())321322 self.redirect_cache = {}323324 def __enter__(self):325 return self326327 def __exit__(self, *args):
216 unmodified lines
544 # Guard against that specific failure case.545 if not isinstance(request, PreparedRequest):546 raise ValueError('You can only send PreparedRequests.')547548 while request.url in self.redirect_cache:549 request.url = self.redirect_cache.get(request.url)550551 # Set up variables needed for resolve_redirects and dispatching of hooks552 allow_redirects = kwargs.pop('allow_redirects', True)553 stream = kwargs.get('stream')554 timeout = kwargs.get('timeout')
91 unmodified lines