Invalidate cached responses after POST - #461
Open
marcelmaatkamp wants to merge 1 commit into
Open
Conversation
RFC 9111 4.4 requires invalidation of the target URI on a non-error response to any unsafe method, and names POST explicitly. invalidating_methods listed PUT, PATCH and DELETE only, so a successful POST left a cached GET for the same URL in place. The added test asserts on the GET that follows the POST rather than on the POST response itself, so it fails without the change.
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
CacheControlAdapter.invalidating_methodslistsPUT,PATCHandDELETE, but notPOST.A successful POST therefore leaves a previously cached GET for the same URL in place, and the
next GET is served from the cache with the pre-POST body.
RFC 9111 §4.4 requires invalidation on any unsafe method and names POST in the first sentence:
Reproduction
Against a server whose GET body changes after each POST:
Same server, same handler, same headers; only the method differs.
The change
One entry added to
invalidating_methods, plus a test.The three existing tests (
test_put_invalidates_cacheand friends) assertnot r2.from_cacheonthe response to the unsafe request itself, which is never served from cache regardless. The new
test asserts on the GET that follows, so it fails without the fix:
With the change, the full suite passes (105 tests).
Scope
This does not implement the
MAYpart of §4.4 (invalidating URIs fromLocationandContent-Location), nor the "methods whose safety is unknown" clause. Both are separate changes.