diff --git a/spring-web/src/main/java/org/springframework/http/CacheControl.java b/spring-web/src/main/java/org/springframework/http/CacheControl.java index a9b4aea11c..315dd0a4d3 100644 --- a/spring-web/src/main/java/org/springframework/http/CacheControl.java +++ b/spring-web/src/main/java/org/springframework/http/CacheControl.java @@ -252,47 +252,47 @@ 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 */ 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) { diff --git a/spring-web/src/main/java/org/springframework/http/HttpHeaders.java b/spring-web/src/main/java/org/springframework/http/HttpHeaders.java index bca45349b5..690b276306 100644 --- a/spring-web/src/main/java/org/springframework/http/HttpHeaders.java +++ b/spring-web/src/main/java/org/springframework/http/HttpHeaders.java @@ -43,18 +43,17 @@ import org.springframework.util.MultiValueMap; import org.springframework.util.StringUtils; /** - * Represents HTTP request and response headers, mapping string header names to a list of string values. + * A data structure representing HTTP request or response headers, mapping String header names + * to a list of String values, also offering accessors for common application-level data types. * - *

In addition to the normal methods defined by {@link Map}, this class offers the following - * convenience methods: + *

In addition to the regular methods defined by {@link Map}, this class offers many common + * convenience methods, for example: *

* - *

Inspired by {@code com.sun.net.httpserver.Headers}. - * * @author Arjen Poutsma * @author Sebastien Deleuze * @author Brian Clozel @@ -66,6 +65,7 @@ public class HttpHeaders implements MultiValueMap, Serializable private static final long serialVersionUID = -8578554704772377436L; + /** * The HTTP {@code Accept} header field name. * @see Section 5.3.2 of RFC 7231 @@ -390,7 +390,7 @@ public class HttpHeaders implements MultiValueMap, 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); @@ -744,8 +744,8 @@ public class HttpHeaders implements MultiValueMap, Serializable * as specified by the {@code Content-Type} header. */ public void setContentType(MediaType mediaType) { - Assert.isTrue(!mediaType.isWildcardType(), "'Content-Type' cannot contain wildcard type '*'"); - Assert.isTrue(!mediaType.isWildcardSubtype(), "'Content-Type' cannot contain wildcard subtype '*'"); + Assert.isTrue(!mediaType.isWildcardType(), "Content-Type cannot contain wildcard type '*'"); + Assert.isTrue(!mediaType.isWildcardSubtype(), "Content-Type cannot contain wildcard subtype '*'"); set(CONTENT_TYPE, mediaType.toString()); } diff --git a/spring-web/src/main/java/org/springframework/http/ResponseEntity.java b/spring-web/src/main/java/org/springframework/http/ResponseEntity.java index b8cbf6d984..efef0a8f01 100644 --- a/spring-web/src/main/java/org/springframework/http/ResponseEntity.java +++ b/spring-web/src/main/java/org/springframework/http/ResponseEntity.java @@ -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. @@ -63,6 +63,7 @@ import org.springframework.util.ObjectUtils; * @author Arjen Poutsma * @author Brian Clozel * @since 3.0.2 + * @param the body type * @see #getStatusCode() */ public class ResponseEntity extends HttpEntity { @@ -295,8 +296,8 @@ public class ResponseEntity extends HttpEntity { /** * Defines a builder that adds headers to the response entity. - * @param the builder subclass * @since 4.1 + * @param the builder subclass */ public interface HeadersBuilder> { @@ -494,7 +495,7 @@ public class ResponseEntity extends HttpEntity { public BodyBuilder cacheControl(CacheControl cacheControl) { String ccValue = cacheControl.getHeaderValue(); if (ccValue != null) { - this.headers.setCacheControl(cacheControl.getHeaderValue()); + this.headers.setCacheControl(ccValue); } return this; }