diff options
| author | Jordan Cook <jordan.cook@pioneer.com> | 2022-04-10 12:15:46 -0500 |
|---|---|---|
| committer | Jordan Cook <jordan.cook@pioneer.com> | 2022-04-10 14:23:43 -0500 |
| commit | d39fbfac0192fc9a2dc825dc17ede29776863f5f (patch) | |
| tree | f222add93c23c4fabd68be204da86f8eb616ad90 /requests_cache | |
| parent | 4a593b0c16aa96d5912fb6605dec46b0dc4bf66e (diff) | |
| download | requests-cache-d39fbfac0192fc9a2dc825dc17ede29776863f5f.tar.gz | |
Add default list of ignored_parameters for most common authentication params/headers
Diffstat (limited to 'requests_cache')
| -rw-r--r-- | requests_cache/cache_keys.py | 5 | ||||
| -rw-r--r-- | requests_cache/session.py | 6 | ||||
| -rw-r--r-- | requests_cache/settings.py | 5 |
3 files changed, 10 insertions, 6 deletions
diff --git a/requests_cache/cache_keys.py b/requests_cache/cache_keys.py index 8a1582c..99e7904 100644 --- a/requests_cache/cache_keys.py +++ b/requests_cache/cache_keys.py @@ -42,7 +42,7 @@ def create_key( Args: request: Request object to generate a cache key from - ignored_parameters: Request parames, headers, and/or body params to not match against + ignored_parameters: Request paramters, headers, and/or JSON body params to exclude match_headers: Match only the specified headers, or ``True`` to match all headers request_kwargs: Request arguments to generate a cache key from """ @@ -95,8 +95,7 @@ def normalize_request( Args: request: Request object to normalize - ignored_parameters: Request parames, headers, and/or body params to not match against and - to remove from the request + ignored_parameters: Request paramters, headers, and/or JSON body params to exclude """ if isinstance(request, Request): norm_request: AnyPreparedRequest = Session().prepare_request(request) diff --git a/requests_cache/session.py b/requests_cache/session.py index 3a1b1a3..99d0509 100644 --- a/requests_cache/session.py +++ b/requests_cache/session.py @@ -31,6 +31,7 @@ from .models import AnyResponse, CachedResponse, OriginalResponse from .serializers import SerializerPipeline from .settings import ( DEFAULT_CACHE_NAME, + DEFAULT_IGNORED_PARAMS, DEFAULT_METHODS, DEFAULT_STATUS_CODES, CacheSettings, @@ -62,7 +63,7 @@ class CacheMixin(MIXIN_BASE): cache_control: bool = False, allowable_codes: Iterable[int] = DEFAULT_STATUS_CODES, allowable_methods: Iterable[str] = DEFAULT_METHODS, - ignored_parameters: Iterable[str] = None, + ignored_parameters: Iterable[str] = DEFAULT_IGNORED_PARAMS, match_headers: Union[Iterable[str], bool] = False, filter_fn: FilterCallback = None, key_fn: KeyCallback = None, @@ -335,7 +336,8 @@ class CachedSession(CacheMixin, OriginalSession): allowable_methods: Cache only responses for one of these HTTP methods match_headers: Match request headers when reading from the cache; may be either ``True`` or a list of specific headers to match - ignored_parameters: List of request parameters to not match against, and exclude from the cache + ignored_parameters: Request paramters, headers, and/or JSON body params to exclude from both + request matching and cached request data stale_if_error: Return stale cache data if a new request raises an exception filter_fn: Response filtering function that indicates whether or not a given response should be cached. See :ref:`custom-filtering` for details. diff --git a/requests_cache/settings.py b/requests_cache/settings.py index 5a7cc6f..62a6c8b 100644 --- a/requests_cache/settings.py +++ b/requests_cache/settings.py @@ -11,6 +11,9 @@ DEFAULT_CACHE_NAME = 'http_cache' DEFAULT_METHODS = ('GET', 'HEAD') DEFAULT_STATUS_CODES = (200,) +# Default params and/or headers that are excluded from cache keys and redacted from cached responses +DEFAULT_IGNORED_PARAMS = ('Authorization', 'X-API-KEY', 'access_token', 'api_key') + # Signatures for user-provided callbacks FilterCallback = Callable[[Response], bool] KeyCallback = Callable[..., str] @@ -30,7 +33,7 @@ class CacheSettings: disabled: bool = field(default=False) expire_after: ExpirationTime = field(default=None) filter_fn: FilterCallback = field(default=None) - ignored_parameters: Iterable[str] = field(default=None) + ignored_parameters: Iterable[str] = field(default=DEFAULT_IGNORED_PARAMS) key_fn: KeyCallback = field(default=None) match_headers: Union[Iterable[str], bool] = field(default=False) only_if_cached: bool = field(default=False) |
