From 33d6e5e8e9c33b0d2d2453a0f78f6383214314d6 Mon Sep 17 00:00:00 2001 From: Sangmin Park Date: Mon, 14 Oct 2024 00:50:36 +0900 Subject: [PATCH 1/3] remove unnecessary else --- .../springframework/web/context/request/ServletWebRequest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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..eccba01ea66e 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 @@ -213,7 +213,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; } From 645842a21bf8f6f96a728dae184892758db02465 Mon Sep 17 00:00:00 2001 From: Sangmin Park Date: Mon, 14 Oct 2024 11:00:25 +0900 Subject: [PATCH 2/3] Refactor if statement for improved readability --- .../web/context/request/ServletWebRequest.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 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 eccba01ea66e..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)) { From de2af0a5a476faa9afcbcb49d34ee9a94d213311 Mon Sep 17 00:00:00 2001 From: Sangmin Park Date: Mon, 14 Oct 2024 11:00:57 +0900 Subject: [PATCH 3/3] Replace @code with @link for checkNotModified reference in Javadoc --- .../org/springframework/web/context/request/WebRequest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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