Skip to content

Commit

Permalink
WIP: Fix parsing HTTP dates from response headers
Browse files Browse the repository at this point in the history
  • Loading branch information
JWCook committed Jul 27, 2021
1 parent 3ea5751 commit 1c11937
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
4 changes: 4 additions & 0 deletions HISTORY.md
@@ -1,5 +1,9 @@
# History

## 0.4.3 (2021-07-27)
* Fix bug in which reponse header `Expires` was used for cache expiration even with `cache_control=False`
* Fix bug in which HTTP dates parsed from response headers weren't converted to UTC

## 0.4.2 (2021-07-26)
* Fix handling of `CachedResponse.encoding` when the response body is `None`

Expand Down
2 changes: 1 addition & 1 deletion aiohttp_client_cache/__init__.py
@@ -1,4 +1,4 @@
__version__ = '0.4.2'
__version__ = '0.4.3'

# flake8: noqa: F401, F403
try:
Expand Down
7 changes: 4 additions & 3 deletions aiohttp_client_cache/cache_control.py
Expand Up @@ -138,14 +138,15 @@ def coalesce(*values: Any, default=None) -> Any:
def get_expiration_datetime(expire_after: ExpirationTime) -> Optional[datetime]:
"""Convert an expiration value in any supported format to an absolute datetime"""
logger.debug(f'Determining expiration time based on: {expire_after}')
if isinstance(expire_after, str):
expire_after = parse_http_date(expire_after)
if expire_after is None or expire_after == -1:
return None
elif isinstance(expire_after, datetime):
if isinstance(expire_after, datetime):
return to_utc(expire_after)
elif isinstance(expire_after, str):
return parse_http_date(expire_after)

if not isinstance(expire_after, timedelta):
assert isinstance(expire_after, (int, float))
expire_after = timedelta(seconds=expire_after)
return datetime.utcnow() + expire_after

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
@@ -1,6 +1,6 @@
[tool.poetry]
name = "aiohttp-client-cache"
version = "0.4.2"
version = "0.4.3"
description = "Persistent cache for aiohttp requests"
authors = ["Jordan Cook"]
license = "MIT License"
Expand Down
2 changes: 1 addition & 1 deletion test/conftest.py
Expand Up @@ -28,7 +28,7 @@
]

HTTPDATE_STR = 'Fri, 16 APR 2021 21:13:00 GMT'
HTTPDATE_DATETIME = datetime(2021, 4, 16, 21, 13, tzinfo=timezone.utc)
HTTPDATE_DATETIME = datetime(2021, 4, 16, 21, 13)


# Configure logging for pytest session
Expand Down

0 comments on commit 1c11937

Please sign in to comment.