Skip to content
Myr

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

1 file+0 added−26 removed

modified:requests/sessions.py-26 removed
11 unmodified lines
12import time13from collections import Mapping14from datetime import timedelta1516from urllib3._collections import RecentlyUsedContainer1716from .auth import _basic_auth_str17from .compat import cookielib, is_py3, OrderedDict, urljoin, urlparse18from .cookies import (19 cookiejar_from_dict, extract_cookies_to_jar, RequestsCookieJar, merge_cookies)
16 unmodified lines
3637# formerly defined here, reexposed here for backward compatibility38from .models import REDIRECT_STATI3942REDIRECT_CACHE_SIZE = 10004340# Preferred clock, based on which one is more accurate on a given system.41if platform.system() == 'Windows':42 try: # Python 3.3+43 preferred_clock = time.perf_counter
109 unmodified lines
153 else:154 url = requote_uri(url)155156 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.url157158 self.rebuild_method(prepared_request, resp)159160 # https://github.com/kennethreitz/requests/issues/1084
224 unmodified lines
385 self.adapters = OrderedDict()386 self.mount('https://', HTTPAdapter())387 self.mount('http://', HTTPAdapter())388396 # Only store 1000 redirects to prevent using infinite memory397 self.redirect_cache = RecentlyUsedContainer(REDIRECT_CACHE_SIZE)398389 def __enter__(self):390 return self391392 def __exit__(self, *args):
219 unmodified lines
612 allow_redirects = kwargs.pop('allow_redirects', True)613 stream = kwargs.get('stream')614 hooks = request.hooks615626 # 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_url635616 # Get the appropriate adapter to use617 adapter = self.get_adapter(url=request.url)618619 # Start time (approximately) of the request
104 unmodified lines
724 self.adapters[key] = self.adapters.pop(key)725726 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 state729730 def __setstate__(self, state):752 redirect_cache = state.pop('redirect_cache', {})731 for attr, value in state.items():732 setattr(self, attr, value)733756 self.redirect_cache = RecentlyUsedContainer(REDIRECT_CACHE_SIZE)757 for redirect, to in redirect_cache.items():758 self.redirect_cache[redirect] = to734760735def session():736 """737 Returns a :class:`Session` for context-management.738
4 unmodified lines