Polishing

This commit is contained in:
Juergen Hoeller
2018-12-11 11:14:23 +01:00
parent 693ad3c1f5
commit a9b453d79f
14 changed files with 75 additions and 80 deletions

View File

@@ -449,7 +449,7 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
* @since 5.0
*/
public void setAcceptLanguage(List<Locale.LanguageRange> languages) {
Assert.notNull(languages, "'languages' must not be null");
Assert.notNull(languages, "LanguageRange List must not be null");
DecimalFormat decimal = new DecimalFormat("0.0", DECIMAL_FORMAT_SYMBOLS);
List<String> values = languages.stream()
.map(range ->
@@ -762,7 +762,7 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
* @see #getContentDisposition()
*/
public void setContentDispositionFormData(String name, @Nullable String filename) {
Assert.notNull(name, "'name' must not be null");
Assert.notNull(name, "Name must not be null");
ContentDisposition.Builder disposition = ContentDisposition.builder("form-data").name(name);
if (filename != null) {
disposition.filename(filename);
@@ -849,8 +849,8 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
*/
public void setContentType(@Nullable MediaType mediaType) {
if (mediaType != null) {
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());
}
else {
@@ -1222,13 +1222,6 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
set(headerName, formatDate(date));
}
// Package private: also used in ResponseCookie..
static String formatDate(long date) {
Instant instant = Instant.ofEpochMilli(date);
ZonedDateTime time = ZonedDateTime.ofInstant(instant, GMT);
return DATE_FORMATTERS[0].format(time);
}
/**
* Parse the first header value for the given header name as a date,
* return -1 if there is no value, or raise {@link IllegalArgumentException}
@@ -1330,10 +1323,7 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
List<String> result = new ArrayList<>();
for (String value : values) {
if (value != null) {
String[] tokens = StringUtils.tokenizeToStringArray(value, ",");
for (String token : tokens) {
result.add(token);
}
Collections.addAll(result, StringUtils.tokenizeToStringArray(value, ","));
}
}
return result;
@@ -1392,7 +1382,7 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
*/
protected String toCommaDelimitedString(List<String> headerValues) {
StringBuilder builder = new StringBuilder();
for (Iterator<String> it = headerValues.iterator(); it.hasNext(); ) {
for (Iterator<String> it = headerValues.iterator(); it.hasNext();) {
String val = it.next();
builder.append(val);
if (it.hasNext()) {
@@ -1565,4 +1555,11 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
return (headers.readOnly ? headers : new HttpHeaders(headers, true));
}
// Package-private: used in ResponseCookie
static String formatDate(long date) {
Instant instant = Instant.ofEpochMilli(date);
ZonedDateTime time = ZonedDateTime.ofInstant(instant, GMT);
return DATE_FORMATTERS[0].format(time);
}
}

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.
@@ -64,6 +64,7 @@ import org.springframework.util.ObjectUtils;
* @author Arjen Poutsma
* @author Brian Clozel
* @since 3.0.2
* @param <T> the body type
* @see #getStatusCode()
*/
public class ResponseEntity<T> extends HttpEntity<T> {
@@ -293,8 +294,8 @@ public class ResponseEntity<T> extends HttpEntity<T> {
/**
* Defines a builder that adds headers to the response entity.
* @param <B> the builder subclass
* @since 4.1
* @param <B> the builder subclass
*/
public interface HeadersBuilder<B extends HeadersBuilder<B>> {