diff options
author | Ian Cordasco <icordasc+github@coglib.com> | 2014-11-07 14:18:41 -0600 |
---|---|---|
committer | Ian Cordasco <icordasc+github@coglib.com> | 2014-11-07 14:18:41 -0600 |
commit | 431282e77888e6601991d8c1e2481b3692f4194a (patch) | |
tree | e2dbb518a37be1f8bb413dc71dd54a9c39b4d09f | |
parent | 1c52d15d9772e459add567cbdc9d38a284a8d939 (diff) | |
parent | 387c8f852cbb6ee2bdbb073b23871e18b7767d53 (diff) | |
download | python-requests-431282e77888e6601991d8c1e2481b3692f4194a.tar.gz |
Merge pull request #2299 from mattrobenolt/master
Cap the redirect_cache size to prevent memory abuse
-rw-r--r-- | requests/sessions.py | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/requests/sessions.py b/requests/sessions.py index dfce7cf9..c2f42b14 100644 --- a/requests/sessions.py +++ b/requests/sessions.py @@ -21,6 +21,7 @@ from .hooks import default_hooks, dispatch_hook from .utils import to_key_val_list, default_headers, to_native_string from .exceptions import ( TooManyRedirects, InvalidSchema, ChunkedEncodingError, ContentDecodingError) +from .packages.urllib3._collections import RecentlyUsedContainer from .structures import CaseInsensitiveDict from .adapters import HTTPAdapter @@ -327,7 +328,8 @@ class Session(SessionRedirectMixin): self.mount('https://', HTTPAdapter()) self.mount('http://', HTTPAdapter()) - self.redirect_cache = {} + # Only store 1000 redirects to prevent using infinite memory + self.redirect_cache = RecentlyUsedContainer(1000) def __enter__(self): return self |