Skip to content

Commit 7377764

Browse files
committed
Polishing
1 parent 288c97b commit 7377764

File tree

6 files changed

+31
-28
lines changed

6 files changed

+31
-28
lines changed

spring-web/src/main/java/org/springframework/http/CacheControl.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -253,48 +253,48 @@ public CacheControl staleIfError(long staleIfError, TimeUnit unit) {
253253

254254

255255
/**
256-
* Return the "Cache-Control" header value.
257-
* @return {@code null} if no directive was added, or the header value otherwise
256+
* Return the "Cache-Control" header value, if any.
257+
* @return the header value, or {@code null} if no directive was added
258258
*/
259259
@Nullable
260260
public String getHeaderValue() {
261-
StringBuilder ccValue = new StringBuilder();
261+
StringBuilder headerValue = new StringBuilder();
262262
if (this.maxAge != -1) {
263-
appendDirective(ccValue, "max-age=" + Long.toString(this.maxAge));
263+
appendDirective(headerValue, "max-age=" + this.maxAge);
264264
}
265265
if (this.noCache) {
266-
appendDirective(ccValue, "no-cache");
266+
appendDirective(headerValue, "no-cache");
267267
}
268268
if (this.noStore) {
269-
appendDirective(ccValue, "no-store");
269+
appendDirective(headerValue, "no-store");
270270
}
271271
if (this.mustRevalidate) {
272-
appendDirective(ccValue, "must-revalidate");
272+
appendDirective(headerValue, "must-revalidate");
273273
}
274274
if (this.noTransform) {
275-
appendDirective(ccValue, "no-transform");
275+
appendDirective(headerValue, "no-transform");
276276
}
277277
if (this.cachePublic) {
278-
appendDirective(ccValue, "public");
278+
appendDirective(headerValue, "public");
279279
}
280280
if (this.cachePrivate) {
281-
appendDirective(ccValue, "private");
281+
appendDirective(headerValue, "private");
282282
}
283283
if (this.proxyRevalidate) {
284-
appendDirective(ccValue, "proxy-revalidate");
284+
appendDirective(headerValue, "proxy-revalidate");
285285
}
286286
if (this.sMaxAge != -1) {
287-
appendDirective(ccValue, "s-maxage=" + Long.toString(this.sMaxAge));
287+
appendDirective(headerValue, "s-maxage=" + this.sMaxAge);
288288
}
289289
if (this.staleIfError != -1) {
290-
appendDirective(ccValue, "stale-if-error=" + Long.toString(this.staleIfError));
290+
appendDirective(headerValue, "stale-if-error=" + this.staleIfError);
291291
}
292292
if (this.staleWhileRevalidate != -1) {
293-
appendDirective(ccValue, "stale-while-revalidate=" + Long.toString(this.staleWhileRevalidate));
293+
appendDirective(headerValue, "stale-while-revalidate=" + this.staleWhileRevalidate);
294294
}
295295

296-
String ccHeaderValue = ccValue.toString();
297-
return (StringUtils.hasText(ccHeaderValue) ? ccHeaderValue : null);
296+
String valueString = headerValue.toString();
297+
return (StringUtils.hasText(valueString) ? valueString : null);
298298
}
299299

300300
private void appendDirective(StringBuilder builder, String value) {

spring-web/src/main/java/org/springframework/http/HttpHeaders.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,7 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
7272

7373
private static final long serialVersionUID = -8578554704772377436L;
7474

75-
/**
76-
* The empty {@code HttpHeaders} instance (immutable).
77-
*/
78-
public static final HttpHeaders EMPTY = new HttpHeaders(new LinkedHashMap<>(), true);
75+
7976
/**
8077
* The HTTP {@code Accept} header field name.
8178
* @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
377374
*/
378375
public static final String WWW_AUTHENTICATE = "WWW-Authenticate";
379376

377+
378+
/**
379+
* The empty {@code HttpHeaders} instance (immutable).
380+
*/
381+
public static final HttpHeaders EMPTY = new HttpHeaders(new LinkedHashMap<>(), true);
382+
380383
/**
381384
* Pattern matching ETag multiple field values in headers such as "If-Match", "If-None-Match".
382385
* @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
394397
private static final DateTimeFormatter[] DATE_FORMATTERS = new DateTimeFormatter[] {
395398
DateTimeFormatter.RFC_1123_DATE_TIME,
396399
DateTimeFormatter.ofPattern("EEEE, dd-MMM-yy HH:mm:ss zz", Locale.US),
397-
DateTimeFormatter.ofPattern("EEE MMM dd HH:mm:ss yyyy",Locale.US).withZone(GMT)
400+
DateTimeFormatter.ofPattern("EEE MMM dd HH:mm:ss yyyy", Locale.US).withZone(GMT)
398401
};
399402

400403

@@ -404,7 +407,7 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
404407

405408

406409
/**
407-
* Constructs a new, empty instance of the {@code HttpHeaders} object.
410+
* Construct a new, empty instance of the {@code HttpHeaders} object.
408411
*/
409412
public HttpHeaders() {
410413
this(new LinkedCaseInsensitiveMap<>(8, Locale.ENGLISH), false);

spring-web/src/main/java/org/springframework/http/ResponseEntity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ public BodyBuilder location(URI location) {
491491
public BodyBuilder cacheControl(CacheControl cacheControl) {
492492
String ccValue = cacheControl.getHeaderValue();
493493
if (ccValue != null) {
494-
this.headers.setCacheControl(cacheControl.getHeaderValue());
494+
this.headers.setCacheControl(ccValue);
495495
}
496496
return this;
497497
}

spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultEntityResponseBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public EntityResponse.Builder<T> location(URI location) {
172172
public EntityResponse.Builder<T> cacheControl(CacheControl cacheControl) {
173173
String ccValue = cacheControl.getHeaderValue();
174174
if (ccValue != null) {
175-
this.headers.setCacheControl(cacheControl.getHeaderValue());
175+
this.headers.setCacheControl(ccValue);
176176
}
177177
return this;
178178
}

spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultServerResponseBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public ServerResponse.BodyBuilder location(URI location) {
172172
public ServerResponse.BodyBuilder cacheControl(CacheControl cacheControl) {
173173
String ccValue = cacheControl.getHeaderValue();
174174
if (ccValue != null) {
175-
this.headers.setCacheControl(cacheControl.getHeaderValue());
175+
this.headers.setCacheControl(ccValue);
176176
}
177177
return this;
178178
}

spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceWebHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,9 @@ public Mono<Void> handle(ServerWebExchange exchange) {
283283

284284
// Apply cache settings, if any
285285
if (getCacheControl() != null) {
286-
String value = getCacheControl().getHeaderValue();
287-
if (value != null) {
288-
exchange.getResponse().getHeaders().setCacheControl(value);
286+
String ccValue = getCacheControl().getHeaderValue();
287+
if (ccValue != null) {
288+
exchange.getResponse().getHeaders().setCacheControl(ccValue);
289289
}
290290
}
291291

0 commit comments

Comments
 (0)