Polishing
This commit is contained in:
@@ -253,48 +253,48 @@ public class CacheControl {
|
||||
|
||||
|
||||
/**
|
||||
* Return the "Cache-Control" header value.
|
||||
* @return {@code null} if no directive was added, or the header value otherwise
|
||||
* Return the "Cache-Control" header value, if any.
|
||||
* @return the header value, or {@code null} if no directive was added
|
||||
*/
|
||||
@Nullable
|
||||
public String getHeaderValue() {
|
||||
StringBuilder ccValue = new StringBuilder();
|
||||
StringBuilder headerValue = new StringBuilder();
|
||||
if (this.maxAge != -1) {
|
||||
appendDirective(ccValue, "max-age=" + Long.toString(this.maxAge));
|
||||
appendDirective(headerValue, "max-age=" + this.maxAge);
|
||||
}
|
||||
if (this.noCache) {
|
||||
appendDirective(ccValue, "no-cache");
|
||||
appendDirective(headerValue, "no-cache");
|
||||
}
|
||||
if (this.noStore) {
|
||||
appendDirective(ccValue, "no-store");
|
||||
appendDirective(headerValue, "no-store");
|
||||
}
|
||||
if (this.mustRevalidate) {
|
||||
appendDirective(ccValue, "must-revalidate");
|
||||
appendDirective(headerValue, "must-revalidate");
|
||||
}
|
||||
if (this.noTransform) {
|
||||
appendDirective(ccValue, "no-transform");
|
||||
appendDirective(headerValue, "no-transform");
|
||||
}
|
||||
if (this.cachePublic) {
|
||||
appendDirective(ccValue, "public");
|
||||
appendDirective(headerValue, "public");
|
||||
}
|
||||
if (this.cachePrivate) {
|
||||
appendDirective(ccValue, "private");
|
||||
appendDirective(headerValue, "private");
|
||||
}
|
||||
if (this.proxyRevalidate) {
|
||||
appendDirective(ccValue, "proxy-revalidate");
|
||||
appendDirective(headerValue, "proxy-revalidate");
|
||||
}
|
||||
if (this.sMaxAge != -1) {
|
||||
appendDirective(ccValue, "s-maxage=" + Long.toString(this.sMaxAge));
|
||||
appendDirective(headerValue, "s-maxage=" + this.sMaxAge);
|
||||
}
|
||||
if (this.staleIfError != -1) {
|
||||
appendDirective(ccValue, "stale-if-error=" + Long.toString(this.staleIfError));
|
||||
appendDirective(headerValue, "stale-if-error=" + this.staleIfError);
|
||||
}
|
||||
if (this.staleWhileRevalidate != -1) {
|
||||
appendDirective(ccValue, "stale-while-revalidate=" + Long.toString(this.staleWhileRevalidate));
|
||||
appendDirective(headerValue, "stale-while-revalidate=" + this.staleWhileRevalidate);
|
||||
}
|
||||
|
||||
String ccHeaderValue = ccValue.toString();
|
||||
return (StringUtils.hasText(ccHeaderValue) ? ccHeaderValue : null);
|
||||
String valueString = headerValue.toString();
|
||||
return (StringUtils.hasText(valueString) ? valueString : null);
|
||||
}
|
||||
|
||||
private void appendDirective(StringBuilder builder, String value) {
|
||||
|
||||
@@ -72,10 +72,7 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
|
||||
|
||||
private static final long serialVersionUID = -8578554704772377436L;
|
||||
|
||||
/**
|
||||
* The empty {@code HttpHeaders} instance (immutable).
|
||||
*/
|
||||
public static final HttpHeaders EMPTY = new HttpHeaders(new LinkedHashMap<>(), true);
|
||||
|
||||
/**
|
||||
* The HTTP {@code Accept} header field name.
|
||||
* @see <a href="http://tools.ietf.org/html/rfc7231#section-5.3.2">Section 5.3.2 of RFC 7231</a>
|
||||
@@ -377,6 +374,12 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
|
||||
*/
|
||||
public static final String WWW_AUTHENTICATE = "WWW-Authenticate";
|
||||
|
||||
|
||||
/**
|
||||
* The empty {@code HttpHeaders} instance (immutable).
|
||||
*/
|
||||
public static final HttpHeaders EMPTY = new HttpHeaders(new LinkedHashMap<>(), true);
|
||||
|
||||
/**
|
||||
* Pattern matching ETag multiple field values in headers such as "If-Match", "If-None-Match".
|
||||
* @see <a href="https://tools.ietf.org/html/rfc7232#section-2.3">Section 2.3 of RFC 7232</a>
|
||||
@@ -394,7 +397,7 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
|
||||
private static final DateTimeFormatter[] DATE_FORMATTERS = new DateTimeFormatter[] {
|
||||
DateTimeFormatter.RFC_1123_DATE_TIME,
|
||||
DateTimeFormatter.ofPattern("EEEE, dd-MMM-yy HH:mm:ss zz", Locale.US),
|
||||
DateTimeFormatter.ofPattern("EEE MMM dd HH:mm:ss yyyy",Locale.US).withZone(GMT)
|
||||
DateTimeFormatter.ofPattern("EEE MMM dd HH:mm:ss yyyy", Locale.US).withZone(GMT)
|
||||
};
|
||||
|
||||
|
||||
@@ -404,7 +407,7 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a new, empty instance of the {@code HttpHeaders} object.
|
||||
* Construct a new, empty instance of the {@code HttpHeaders} object.
|
||||
*/
|
||||
public HttpHeaders() {
|
||||
this(new LinkedCaseInsensitiveMap<>(8, Locale.ENGLISH), false);
|
||||
|
||||
@@ -491,7 +491,7 @@ public class ResponseEntity<T> extends HttpEntity<T> {
|
||||
public BodyBuilder cacheControl(CacheControl cacheControl) {
|
||||
String ccValue = cacheControl.getHeaderValue();
|
||||
if (ccValue != null) {
|
||||
this.headers.setCacheControl(cacheControl.getHeaderValue());
|
||||
this.headers.setCacheControl(ccValue);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ class DefaultEntityResponseBuilder<T> implements EntityResponse.Builder<T> {
|
||||
public EntityResponse.Builder<T> cacheControl(CacheControl cacheControl) {
|
||||
String ccValue = cacheControl.getHeaderValue();
|
||||
if (ccValue != null) {
|
||||
this.headers.setCacheControl(cacheControl.getHeaderValue());
|
||||
this.headers.setCacheControl(ccValue);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ class DefaultServerResponseBuilder implements ServerResponse.BodyBuilder {
|
||||
public ServerResponse.BodyBuilder cacheControl(CacheControl cacheControl) {
|
||||
String ccValue = cacheControl.getHeaderValue();
|
||||
if (ccValue != null) {
|
||||
this.headers.setCacheControl(cacheControl.getHeaderValue());
|
||||
this.headers.setCacheControl(ccValue);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -283,9 +283,9 @@ public class ResourceWebHandler implements WebHandler, InitializingBean {
|
||||
|
||||
// Apply cache settings, if any
|
||||
if (getCacheControl() != null) {
|
||||
String value = getCacheControl().getHeaderValue();
|
||||
if (value != null) {
|
||||
exchange.getResponse().getHeaders().setCacheControl(value);
|
||||
String ccValue = getCacheControl().getHeaderValue();
|
||||
if (ccValue != null) {
|
||||
exchange.getResponse().getHeaders().setCacheControl(ccValue);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user