summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordan Cook <jordan.cook.git@proton.me>2022-10-20 13:22:52 -0500
committerJordan Cook <jordan.cook.git@proton.me>2022-10-20 13:26:05 -0500
commitae2a1691ff32df16d987e8985799e95dedda9619 (patch)
tree4825d535ec36600d4b3de2710c995879e4bc5900
parent446bbc87ca37ed0b620317d33eee4121a2a334b8 (diff)
downloadrequests-cache-ae2a1691ff32df16d987e8985799e95dedda9619.tar.gz
Add support for header values as bytes
Fixes #705 (for 0.9)
-rw-r--r--HISTORY.md1
-rw-r--r--requests_cache/cache_control.py7
-rw-r--r--tests/unit/test_cache_control.py1
3 files changed, 8 insertions, 1 deletions
diff --git a/HISTORY.md b/HISTORY.md
index 6fc6d88..7366207 100644
--- a/HISTORY.md
+++ b/HISTORY.md
@@ -5,6 +5,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/cache_control.py b/requests_cache/cache_control.py
index 81fbcac..3a4e739 100644
--- a/requests_cache/cache_control.py
+++ b/requests_cache/cache_control.py
@@ -187,7 +187,12 @@ def get_cache_directives(headers: Mapping) -> Dict:
kv_directives = {}
if headers.get('Cache-Control'):
- cache_directives = headers['Cache-Control'].split(',')
+ cache_control = (
+ headers['Cache-Control'].decode()
+ if isinstance(headers['Cache-Control'], bytes)
+ else headers['Cache-Control']
+ )
+ cache_directives = cache_control.split(',')
kv_directives = dict([split_kv_directive(value) for value in cache_directives])
if 'Expires' in headers:
diff --git a/tests/unit/test_cache_control.py b/tests/unit/test_cache_control.py
index d9140d8..7f0c2de 100644
--- a/tests/unit/test_cache_control.py
+++ b/tests/unit/test_cache_control.py
@@ -65,6 +65,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),
({'Cache-Control': 'max-age=0'}, DO_NOT_CACHE),
({'Cache-Control': 'no-store'}, DO_NOT_CACHE),
],