From: Matt Robenolt Date: Fri, 24 Oct 2014 03:49:18 +0000 (-0700) Subject: Cap the redirect_cache size to prevent memory abuse X-Git-Tag: v2.5.0~11^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=387c8f852cbb6ee2bdbb073b23871e18b7767d53;p=services%2Fpython-requests.git Cap the redirect_cache size to prevent memory abuse --- diff --git a/requests/sessions.py b/requests/sessions.py index d701ff2..75be1da 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