Polishing

This commit is contained in:
Juergen Hoeller
2018-03-31 17:06:33 +02:00
parent 5d54adfb9a
commit b0ed385f84
14 changed files with 62 additions and 93 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -128,10 +128,8 @@ public class ShallowEtagHeaderFilter extends OncePerRequestFilter {
String responseETag = generateETagHeaderValue(responseWrapper.getContentInputStream(), this.writeWeakETag);
rawResponse.setHeader(HEADER_ETAG, responseETag);
String requestETag = request.getHeader(HEADER_IF_NONE_MATCH);
if (requestETag != null
&& (responseETag.equals(requestETag)
|| responseETag.replaceFirst("^W/", "").equals(requestETag.replaceFirst("^W/", ""))
|| "*".equals(requestETag))) {
if (requestETag != null && ("*".equals(requestETag) || responseETag.equals(requestETag) ||
responseETag.replaceFirst("^W/", "").equals(requestETag.replaceFirst("^W/", "")))) {
if (logger.isTraceEnabled()) {
logger.trace("ETag [" + responseETag + "] equal to If-None-Match, sending 304");
}
@@ -165,15 +163,13 @@ public class ShallowEtagHeaderFilter extends OncePerRequestFilter {
* @param response the HTTP response
* @param responseStatusCode the HTTP response status code
* @param inputStream the response body
* @return {@code true} if eligible for ETag generation; {@code false} otherwise
* @return {@code true} if eligible for ETag generation, {@code false} otherwise
*/
protected boolean isEligibleForEtag(HttpServletRequest request, HttpServletResponse response,
int responseStatusCode, InputStream inputStream) {
String method = request.getMethod();
if (responseStatusCode >= 200 && responseStatusCode < 300
&& HttpMethod.GET.matches(method)) {
if (responseStatusCode >= 200 && responseStatusCode < 300 && HttpMethod.GET.matches(method)) {
String cacheControl = null;
if (servlet3Present) {
cacheControl = response.getHeader(HEADER_CACHE_CONTROL);
@@ -194,7 +190,7 @@ public class ShallowEtagHeaderFilter extends OncePerRequestFilter {
* @see org.springframework.util.DigestUtils
*/
protected String generateETagHeaderValue(InputStream inputStream, boolean isWeak) throws IOException {
// length of W/ + 0 + " + 32bits md5 hash + "
// length of W/ + " + 0 + 32bits md5 hash + "
StringBuilder builder = new StringBuilder(37);
if (isWeak) {
builder.append("W/");

View File

@@ -259,10 +259,7 @@ public class UrlPathHelper {
}
c1 = requestUri.charAt(index1);
}
if (c1 == c2) {
continue;
}
else if (ignoreCase && (Character.toLowerCase(c1) == Character.toLowerCase(c2))) {
if (c1 == c2 || (ignoreCase && (Character.toLowerCase(c1) == Character.toLowerCase(c2)))) {
continue;
}
return null;