"""
return ('location' in self.headers and self.status_code in REDIRECT_STATI)
+ @property
+ def is_permanent_redirect(self):
+ """True if this Response one of the permanant versions of redirect"""
+ return ('location' in self.headers and self.status_code in (codes.moved_permanently, codes.permanent_redirect))
+
@property
def apparent_encoding(self):
"""The apparent encoding, provided by the chardet library"""
url = requote_uri(url)
prepared_request.url = to_native_string(url)
+ # cache the url
+ if resp.is_permanent_redirect:
+ self.redirect_cache[req.url] = prepared_request.url
# http://tools.ietf.org/html/rfc7231#section-6.4.4
if (resp.status_code == codes.see_other and
__attrs__ = [
'headers', 'cookies', 'auth', 'timeout', 'proxies', 'hooks',
'params', 'verify', 'cert', 'prefetch', 'adapters', 'stream',
- 'trust_env', 'max_redirects']
+ 'trust_env', 'max_redirects', 'redirect_cache']
def __init__(self):
self.mount('https://', HTTPAdapter())
self.mount('http://', HTTPAdapter())
+ self.redirect_cache = {}
+
def __enter__(self):
return self
if not isinstance(request, PreparedRequest):
raise ValueError('You can only send PreparedRequests.')
+ while request.url in self.redirect_cache:
+ request.url = self.redirect_cache.get(request.url)
+
# Set up variables needed for resolve_redirects and dispatching of hooks
allow_redirects = kwargs.pop('allow_redirects', True)
stream = kwargs.get('stream')