Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cachecontrol/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ def _load_from_cache(self, request: PreparedRequest) -> HTTPResponse | None:
if "Range" in request.headers:
return None

cache_url = request.url
assert cache_url is not None
assert request.url is not None
cache_url = self.cache_url(request.url)
cache_data = self.cache.get(cache_url)
if cache_data is None:
logger.debug("No cache entry available")
Expand Down
15 changes: 15 additions & 0 deletions tests/test_regressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@ def test_file_cache_recognizes_consumed_file_handle(self, url):
s.close()


class TestCacheKeyNormalization:
def test_fragment_in_url_still_hits_the_cache(self, url):
"""The cache is keyed on the normalized URL, which drops the fragment.

Reads have to normalize too, otherwise a request for a URL carrying a
fragment stores an entry it can never look up again.
"""
s = CacheControl(Session())
the_url = url + "cache_60#section"
s.get(the_url)
r = s.get(the_url)
assert r.from_cache
s.close()


def test_getattr_during_gc():
s = CallbackFileWrapper(None, None)
# normal behavior:
Expand Down