Merge pull request #4100 from bcongdon/remove-redirect-cache
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Remove session redirect cache
authored by Kenneth Reitz · committed by GitHub · parents c77911c, 86f8cb8 · Browse files · 1 file·+0 added−26 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+0 added−26 removed
- other:+0 added−26 removed
Provenance
- Commit
68076a7- Tree
302da2a- Author
Kenneth Reitz <me@kennethreitz.org>- Committer
GitHub <noreply@github.com>- Parent 1
c77911c- Parent 2
86f8cb8
1 file changed+0 added−26 removed
modified:requests/sessions.py-26 removed
11 unmodified lines12 import time13 from collections import Mapping14 from datetime import timedelta15 16-from urllib3._collections import RecentlyUsedContainer17-16 from .auth import _basic_auth_str17 from .compat import cookielib, is_py3, OrderedDict, urljoin, urlparse18 from .cookies import (19 cookiejar_from_dict, extract_cookies_to_jar, RequestsCookieJar, merge_cookies)16 unmodified lines36 37 # formerly defined here, reexposed here for backward compatibility38 from .models import REDIRECT_STATI39 42-REDIRECT_CACHE_SIZE = 100043-40 # Preferred clock, based on which one is more accurate on a given system.41 if platform.system() == 'Windows':42 try: # Python 3.3+43 preferred_clock = time.perf_counter109 unmodified lines153 else:154 url = requote_uri(url)155 156 prepared_request.url = to_native_string(url)161- # Cache the url, unless it redirects to itself.162- if resp.is_permanent_redirect and req.url != prepared_request.url:163- self.redirect_cache[req.url] = prepared_request.url157 158 self.rebuild_method(prepared_request, resp)159 160 # https://github.com/kennethreitz/requests/issues/1084224 unmodified lines385 self.adapters = OrderedDict()386 self.mount('https://', HTTPAdapter())387 self.mount('http://', HTTPAdapter())388 396- # Only store 1000 redirects to prevent using infinite memory397- self.redirect_cache = RecentlyUsedContainer(REDIRECT_CACHE_SIZE)398-389 def __enter__(self):390 return self391 392 def __exit__(self, *args):219 unmodified lines612 allow_redirects = kwargs.pop('allow_redirects', True)613 stream = kwargs.get('stream')614 hooks = request.hooks615 626- # Resolve URL in redirect cache, if available.627- if allow_redirects:628- checked_urls = set()629- while request.url in self.redirect_cache:630- checked_urls.add(request.url)631- new_url = self.redirect_cache.get(request.url)632- if new_url in checked_urls:633- break634- request.url = new_url635-616 # Get the appropriate adapter to use617 adapter = self.get_adapter(url=request.url)618 619 # Start time (approximately) of the request104 unmodified lines724 self.adapters[key] = self.adapters.pop(key)725 726 def __getstate__(self):727 state = dict((attr, getattr(self, attr, None)) for attr in self.__attrs__)748- state['redirect_cache'] = dict(self.redirect_cache)728 return state729 730 def __setstate__(self, state):752- redirect_cache = state.pop('redirect_cache', {})731 for attr, value in state.items():732 setattr(self, attr, value)733 756- self.redirect_cache = RecentlyUsedContainer(REDIRECT_CACHE_SIZE)757- for redirect, to in redirect_cache.items():758- self.redirect_cache[redirect] = to734 760-735 def session():736 """737 Returns a :class:`Session` for context-management.738 4 unmodified lines