summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordan Cook <jordan.cook.git@proton.me>2022-10-20 13:25:21 -0500
committerGitHub <noreply@github.com>2022-10-20 13:25:21 -0500
commitd502885c4eb2f6dd9c7b760ea1ee5784dde3809f (patch)
treef16d1135f034ed8af8ac2aa0441efd7ba1072755
parentacdbe633a80ae9a8d9deb20c1255124f7e159b33 (diff)
parent10fba0bcb772a2e46e758e4173d1ab99ec287e93 (diff)
downloadrequests-cache-d502885c4eb2f6dd9c7b760ea1ee5784dde3809f.tar.gz
Merge pull request #709 from requests-cache/header-bytes
Add support for header values as bytes
-rw-r--r--HISTORY.md12
-rw-r--r--requests_cache/policy/directives.py4
-rw-r--r--tests/unit/policy/test_actions.py1
3 files changed, 11 insertions, 6 deletions
diff --git a/HISTORY.md b/HISTORY.md
index d4a03bb..790cdf8 100644
--- a/HISTORY.md
+++ b/HISTORY.md
@@ -88,16 +88,19 @@
* `OriginalResponse.cache_key` and `expires` will be populated for any new response that was written to the cache
* Add request wrapper methods with return type hints for all HTTP methods (`CachedSession.get()`, `head()`, etc.)
-**Bugfixes:**
+**Compatibility fixes:**
+* Add support for header values as bytes for compatibility with OAuth1 features of `requests-oauthlib`
+* Add compatibility with cattrs 22.1+
+* Fix forwarding connection parameters passed to `RedisCache` for redis-py 4.2 and python <=3.8
+* Fix forwarding connection parameters passed to `MongoCache` for pymongo 4.1 and python <=3.8
+
+**Other Bugfixes:**
* Fix usage of memory backend with `install_cache()`
* Fix issue on Windows with occasional missing `CachedResponse.created_at` timestamp
* Add `CachedRequest.path_url` property for compatibility with `RequestEncodingMixin`
* Fix potential `AttributeError` due to undetected imports when requests-cache is bundled in a PyInstaller package
* Fix `AttributeError` when attempting to unpickle a `CachedSession` object, and instead disable
pickling by raising a `NotImplementedError`
-* Add compatibility with cattrs 22.1+
-* Fix forwarding connection parameters passed to `RedisCache` for redis-py 4.2 and python <=3.8
-* Fix forwarding connection parameters passed to `MongoCache` for pymongo 4.1 and python <=3.8
**Dependencies:**
* Replace `appdirs` with `platformdirs`
@@ -138,6 +141,7 @@ Backport fixes from 1.0:
* Fix potential `AttributeError` due to undetected imports when requests-cache is bundled in a PyInstaller package
* Fix `AttributeError` when attempting to unpickle a `CachedSession` object, and instead disable
pickling by raising a `NotImplementedError`
+* Add support for header values as bytes for compatibility with OAuth1 features of `requests-oauthlib`
* Update to cattrs 22.2
## 0.9.6 (2022-08-24)
diff --git a/requests_cache/policy/directives.py b/requests_cache/policy/directives.py
index 889db22..3be50c4 100644
--- a/requests_cache/policy/directives.py
+++ b/requests_cache/policy/directives.py
@@ -4,7 +4,7 @@ from typing import Optional
from attr import define, field
from requests.models import CaseInsensitiveDict
-from .._utils import get_valid_kwargs, try_int
+from .._utils import decode, get_valid_kwargs, try_int
from ..models import RichMixin
from . import HeaderDict, get_expiration_seconds
@@ -33,7 +33,7 @@ class CacheDirectives(RichMixin):
def from_headers(cls, headers: HeaderDict):
"""Parse cache directives and other settings from request or response headers"""
headers = CaseInsensitiveDict(headers)
- directives = headers.get('Cache-Control', '').split(',')
+ directives = decode(headers.get('Cache-Control', '')).split(',')
kv_directives = dict(_split_kv_directive(value) for value in directives)
kwargs = get_valid_kwargs(
cls.__init__, {k.replace('-', '_'): v for k, v in kv_directives.items()}
diff --git a/tests/unit/policy/test_actions.py b/tests/unit/policy/test_actions.py
index f5d4c4a..4ea133c 100644
--- a/tests/unit/policy/test_actions.py
+++ b/tests/unit/policy/test_actions.py
@@ -58,6 +58,7 @@ def test_init(
({'Expires': HTTPDATE_STR}, None), # Only valid for response headers
({'Cache-Control': 'max-age=60'}, 60),
({'Cache-Control': 'public, max-age=60'}, 60),
+ ({'Cache-Control': b'public, max-age=60'}, 60), # requests-oauthlib casts headers to bytes
({'Cache-Control': 'max-age=0'}, EXPIRE_IMMEDIATELY),
],
)