Skip to content

Polish ServletWebRequest and DefaultServerWebExchange #29460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,7 @@ else if (validateIfUnmodifiedSince(lastModifiedTimestamp)) {

private boolean validateIfMatch(@Nullable String eTag) {
Enumeration<String> ifMatchHeaders = getRequest().getHeaders(HttpHeaders.IF_MATCH);
if (SAFE_METHODS.contains(getRequest().getMethod())) {
return false;
}
if (!ifMatchHeaders.hasMoreElements()) {
if (SAFE_METHODS.contains(getRequest().getMethod()) || !ifMatchHeaders.hasMoreElements()) {
return false;
}
this.notModified = matchRequestedETags(ifMatchHeaders, eTag, false);
Expand Down Expand Up @@ -309,7 +306,7 @@ private boolean eTagWeakMatch(@Nullable String first, @Nullable String second) {
return first.equals(second);
}

private void updateResponseStateChanging(String eTag, long lastModifiedTimestamp) {
private void updateResponseStateChanging(@Nullable String eTag, long lastModifiedTimestamp) {
if (this.notModified && getResponse() != null) {
getResponse().setStatus(HttpStatus.PRECONDITION_FAILED.value());
}
Expand All @@ -330,20 +327,18 @@ private boolean validateIfUnmodifiedSince(long lastModifiedTimestamp) {
return true;
}

private boolean validateIfModifiedSince(long lastModifiedTimestamp) {
private void validateIfModifiedSince(long lastModifiedTimestamp) {
if (lastModifiedTimestamp < 0) {
return false;
return;
}
long ifModifiedSince = parseDateHeader(HttpHeaders.IF_MODIFIED_SINCE);
if (ifModifiedSince == -1) {
return false;
if (ifModifiedSince != -1) {
// We will perform this validation...
this.notModified = ifModifiedSince >= (lastModifiedTimestamp / 1000 * 1000);
}
// We will perform this validation...
this.notModified = ifModifiedSince >= (lastModifiedTimestamp / 1000 * 1000);
return true;
}

private void updateResponseIdempotent(String eTag, long lastModifiedTimestamp) {
private void updateResponseIdempotent(@Nullable String eTag, long lastModifiedTimestamp) {
if (getResponse() != null) {
boolean isHttpGetOrHead = SAFE_METHODS.contains(getRequest().getMethod());
if (this.notModified) {
Expand All @@ -354,7 +349,7 @@ private void updateResponseIdempotent(String eTag, long lastModifiedTimestamp) {
}
}

private void addCachingResponseHeaders(String eTag, long lastModifiedTimestamp) {
private void addCachingResponseHeaders(@Nullable String eTag, long lastModifiedTimestamp) {
if (SAFE_METHODS.contains(getRequest().getMethod())) {
if (lastModifiedTimestamp > 0 && parseDateValue(getResponse().getHeader(HttpHeaders.LAST_MODIFIED)) == -1) {
getResponse().setDateHeader(HttpHeaders.LAST_MODIFIED, lastModifiedTimestamp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ private boolean eTagWeakMatch(@Nullable String first, @Nullable String second) {
return first.equals(second);
}

private void updateResponseStateChanging(String eTag, Instant lastModified) {
private void updateResponseStateChanging(@Nullable String eTag, Instant lastModified) {
if (this.notModified) {
getResponse().setStatusCode(HttpStatus.PRECONDITION_FAILED);
}
Expand Down Expand Up @@ -401,17 +401,15 @@ private boolean validateIfUnmodifiedSince(Instant lastModified) {
return true;
}

private boolean validateIfModifiedSince(Instant lastModified) {
private void validateIfModifiedSince(Instant lastModified) {
if (lastModified.isBefore(Instant.EPOCH)) {
return false;
return;
}
long ifModifiedSince = getRequestHeaders().getIfModifiedSince();
if (ifModifiedSince == -1) {
return false;
if (ifModifiedSince != -1) {
// We will perform this validation...
this.notModified = ChronoUnit.SECONDS.between(lastModified, Instant.ofEpochMilli(ifModifiedSince)) >= 0;
}
// We will perform this validation...
this.notModified = ChronoUnit.SECONDS.between(lastModified, Instant.ofEpochMilli(ifModifiedSince)) >= 0;
return true;
}

@Override
Expand Down