summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Cordasco <icordasc+github@coglib.com>2014-11-07 14:18:41 -0600
committerIan Cordasco <icordasc+github@coglib.com>2014-11-07 14:18:41 -0600
commit431282e77888e6601991d8c1e2481b3692f4194a (patch)
treee2dbb518a37be1f8bb413dc71dd54a9c39b4d09f
parent1c52d15d9772e459add567cbdc9d38a284a8d939 (diff)
parent387c8f852cbb6ee2bdbb073b23871e18b7767d53 (diff)
downloadpython-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.py4
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