From ae32227b5062176de13746740901dbbabe6b9afb Mon Sep 17 00:00:00 2001 From: Sangmin Park Date: Mon, 14 Oct 2024 00:50:36 +0900 Subject: [PATCH] Polish ServletWebRequest Closes gh-33698 --- .../web/context/request/ServletWebRequest.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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 554aca37ce9..64690c9495f 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 class ServletWebRequest extends ServletRequestAttributes implements Nativ @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 class ServletWebRequest extends ServletRequestAttributes implements Nativ return this.notModified; } // 2) If-Unmodified-Since - else if (validateIfUnmodifiedSince(lastModifiedTimestamp)) { + if (validateIfUnmodifiedSince(lastModifiedTimestamp)) { updateResponseStateChanging(etag, lastModifiedTimestamp); return this.notModified; }