Repository navigation
Conversation
Refactor tests to parameterize status codes for cached response updates.
Added a test for revalidated redirects with status codes 301 and 308, ensuring proper caching behavior.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
CacheController.update_cached_response()unconditionally sets the cached response's status to 200 after a 304 revalidation. This changes the meaning of cacheable non-200 responses. In particular, an ETag-bearing 301 or 308 becomes a 200 with a Location header, so requests no longer recognizes it as a redirect. The incorrect status is also written back into the cache.Fix
Keep the stored status while refreshing the headers. The 304 is validation of the stored response, not a replacement 200 response (RFC 9111 section 4.3.4). No public API or dependencies change.
Regression coverage
Validation
Using the committed dependency lock and Python 3.12:
uv run --frozen --dev pytest -q: 126 passed.uv run --frozen --dev ruff check: passed.uv run --frozen --dev mypy cachecontrol: passed (12 source files).uv build: wheel and sdist built successfully.git diff --check: passed.The full 126-test suite also passed on Python 3.11. Its mypy check encounters the existing collections.abc.Buffer error in filewrapper.py; the production change is limited to removing the status override.
This contribution was prepared and tested with an AI coding assistant.