Skip to content

Commit 436ae7b

Browse files
Refactor if statement for improved readability
1 parent 9252e74 commit 436ae7b

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

spring-web/src/main/java/org/springframework/web/context/request/ServletWebRequest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public boolean checkNotModified(String etag) {
202202

203203
@Override
204204
public boolean checkNotModified(@Nullable String etag, long lastModifiedTimestamp) {
205-
if (this.notModified) {
205+
if (isNotModified()) {
206206
return true;
207207
}
208208

@@ -213,6 +213,8 @@ public boolean checkNotModified(@Nullable String etag, long lastModifiedTimestam
213213

214214
// Evaluate conditions in order of precedence.
215215
// See https://datatracker.ietf.org/doc/html/rfc9110#section-13.2.2
216+
217+
// 1) If-Match
216218
if (validateIfMatch(etag)) {
217219
updateResponseStateChanging(etag, lastModifiedTimestamp);
218220
return this.notModified;

spring-web/src/main/java/org/springframework/web/server/adapter/DefaultServerWebExchange.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,19 +300,25 @@ public boolean checkNotModified(String etag) {
300300

301301
@Override
302302
public boolean checkNotModified(@Nullable String eTag, Instant lastModified) {
303+
if (isNotModified()) {
304+
return true;
305+
}
306+
303307
HttpStatusCode status = getResponse().getStatusCode();
304-
if (this.notModified || (status != null && !HttpStatus.OK.equals(status))) {
305-
return this.notModified;
308+
if (status != null && !HttpStatus.OK.equals(status)) {
309+
return false;
306310
}
311+
307312
// Evaluate conditions in order of precedence.
308313
// See https://datatracker.ietf.org/doc/html/rfc9110#section-13.2.2
314+
309315
// 1) If-Match
310316
if (validateIfMatch(eTag)) {
311317
updateResponseStateChanging(eTag, lastModified);
312318
return this.notModified;
313319
}
314320
// 2) If-Unmodified-Since
315-
else if (validateIfUnmodifiedSince(lastModified)) {
321+
if (validateIfUnmodifiedSince(lastModified)) {
316322
updateResponseStateChanging(eTag, lastModified);
317323
return this.notModified;
318324
}

0 commit comments

Comments
 (0)