Skip to content

Commit

Permalink
Add support for header values as bytes
Browse files Browse the repository at this point in the history
Fixes #705 (for 0.9)
  • Loading branch information
JWCook committed Oct 20, 2022
1 parent 446bbc8 commit ae2a169
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions HISTORY.md
Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion requests_cache/cache_control.py
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_cache_control.py
Expand Up @@ -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),
],
Expand Down

0 comments on commit ae2a169

Please sign in to comment.