diff --git a/spring-web/src/main/java/org/springframework/web/context/request/ServletWebRequest.java b/spring-web/src/main/java/org/springframework/web/context/request/ServletWebRequest.java index 554aca37ce90..64690c9495f7 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/ServletWebRequest.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/ServletWebRequest.java @@ -202,10 +202,15 @@ public boolean checkNotModified(String etag) { @Override public boolean checkNotModified(@Nullable String etag, long lastModifiedTimestamp) { + if (this.notModified) { + return true; + } + HttpServletResponse response = getResponse(); - if (this.notModified || (response != null && HttpStatus.OK.value() != response.getStatus())) { - return this.notModified; + if (response != null && HttpStatus.OK.value() != response.getStatus()) { + return false; } + // Evaluate conditions in order of precedence. // See https://datatracker.ietf.org/doc/html/rfc9110#section-13.2.2 if (validateIfMatch(etag)) { @@ -213,7 +218,7 @@ public boolean checkNotModified(@Nullable String etag, long lastModifiedTimestam return this.notModified; } // 2) If-Unmodified-Since - else if (validateIfUnmodifiedSince(lastModifiedTimestamp)) { + if (validateIfUnmodifiedSince(lastModifiedTimestamp)) { updateResponseStateChanging(etag, lastModifiedTimestamp); return this.notModified; } diff --git a/spring-web/src/main/java/org/springframework/web/context/request/WebRequest.java b/spring-web/src/main/java/org/springframework/web/context/request/WebRequest.java index e1d4899e9bd4..f3b597d0e4d4 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/WebRequest.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/WebRequest.java @@ -223,7 +223,7 @@ public interface WebRequest extends RequestAttributes { * also with conditional POST/PUT/DELETE requests. *
Note: The HTTP specification recommends * setting both ETag and Last-Modified values, but you can also - * use {@code #checkNotModified(String)} or + * use {@link #checkNotModified(String)} or * {@link #checkNotModified(long)}. * @param etag the entity tag that the application determined * for the underlying resource. This parameter will be padded