Repository navigation
Conversation
Prior to this commit, checkNotModified in ServletWebRequest and DefaultServerWebExchange evaluated the If-Modified-Since precondition for any HTTP method. For a PUT, POST or DELETE request with an If-Modified-Since date that is not before the last modification date, the request was therefore considered not modified and the response status was set to 412 (Precondition Failed), rejecting a request for a resource that had not changed. As specified in RFC 9110, section 13.1.3, a recipient must ignore the If-Modified-Since header field if the request method is neither GET nor HEAD, and the precedence rules in section 13.2.2 only evaluate it for GET and HEAD requests. This commit applies that restriction in both implementations. Signed-off-by: Jialin Chen <cccll2019@gmail.com>
This branch has not been deployed
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.
checkNotModified()inServletWebRequestandDefaultServerWebExchangeevaluatesIf-Modified-Sincefor any HTTPmethod. For a
PUT,POSTorDELETErequest whoseIf-Modified-Sincedate is not before the last modification date, therequest is considered not modified, and since the method is not safe,
the response status is set to 412:
With a last modification date of 2026-01-01T00:00:00Z,
checkNotModified(lastModified)returnstrueand sets the status to412 (with this change, it returns
falseand the request proceeds). Therequest is rejected precisely when the resource has not changed since
the given date.
RFC 9110, section 13.1.3
requires a recipient to ignore the
If-Modified-Sinceheader field "ifthe request method is neither GET nor HEAD", and step 4 of the
precedence rules in
section 13.2.2,
which both implementations follow, only evaluates it for GET and HEAD.
This change applies that restriction in both implementations.
If-MatchandIf-Unmodified-Since, which are the preconditions meantfor conditional
POST,PUTandDELETErequests, are not affected,and neither is
If-Modified-SinceforGETandHEAD.New tests in
ServletWebRequestHttpMethodsTests(forPOST,PUTandDELETE) andDefaultServerWebExchangeCheckNotModifiedTestsfailwithout the change and pass with it.
./gradlew :spring-web:check :spring-webmvc:check :spring-webflux:checkpasses on JDK 25.
This behavior predates the conditional request revision in gh-24881,
and the code is the same on 7.0.x.