提交 0fb8f0b4 编写于 作者: J Juergen Hoeller

Polishing

上级 8760be7d
...@@ -43,7 +43,8 @@ import org.springframework.util.StringUtils; ...@@ -43,7 +43,8 @@ import org.springframework.util.StringUtils;
/** /**
* Represents HTTP request and response headers, mapping string header names to list of string values. * Represents HTTP request and response headers, mapping string header names to list of string values.
* *
* <p>In addition to the normal methods defined by {@link Map}, this class offers the following convenience methods: * <p>In addition to the normal methods defined by {@link Map}, this class offers the following
* convenience methods:
* <ul> * <ul>
* <li>{@link #getFirst(String)} returns the first value associated with a given header name</li> * <li>{@link #getFirst(String)} returns the first value associated with a given header name</li>
* <li>{@link #add(String, String)} adds a header value to the list of values for a header name</li> * <li>{@link #add(String, String)} adds a header value to the list of values for a header name</li>
...@@ -329,9 +330,17 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable ...@@ -329,9 +330,17 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
private static TimeZone GMT = TimeZone.getTimeZone("GMT"); private static TimeZone GMT = TimeZone.getTimeZone("GMT");
private final Map<String, List<String>> headers; private final Map<String, List<String>> headers;
/**
* Constructs a new, empty instance of the {@code HttpHeaders} object.
*/
public HttpHeaders() {
this(new LinkedCaseInsensitiveMap<List<String>>(8, Locale.ENGLISH), false);
}
/** /**
* Private constructor that can create read-only {@code HttpHeader} instances. * Private constructor that can create read-only {@code HttpHeader} instances.
*/ */
...@@ -351,19 +360,6 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable ...@@ -351,19 +360,6 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
} }
} }
/**
* Constructs a new, empty instance of the {@code HttpHeaders} object.
*/
public HttpHeaders() {
this(new LinkedCaseInsensitiveMap<List<String>>(8, Locale.ENGLISH), false);
}
/**
* Returns {@code HttpHeaders} object that can only be read, not written to.
*/
public static HttpHeaders readOnlyHttpHeaders(HttpHeaders headers) {
return new HttpHeaders(headers, true);
}
/** /**
* Set the list of acceptable {@linkplain MediaType media types}, as specified by the {@code Accept} header. * Set the list of acceptable {@linkplain MediaType media types}, as specified by the {@code Accept} header.
...@@ -612,7 +608,6 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable ...@@ -612,7 +608,6 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
* the {@code Expires} header. * the {@code Expires} header.
* <p>The date is returned as the number of milliseconds since January 1, 1970 GMT. * <p>The date is returned as the number of milliseconds since January 1, 1970 GMT.
* Returns -1 when the date is unknown. * Returns -1 when the date is unknown.
*
* @return the expires value * @return the expires value
*/ */
public long getExpires() { public long getExpires() {
...@@ -786,8 +781,6 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable ...@@ -786,8 +781,6 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
return getFirst(UPGRADE); return getFirst(UPGRADE);
} }
// Date methods
/** /**
* Parse the first header value for the given header name as a date, return -1 if * Parse the first header value for the given header name as a date, return -1 if
* there is no value, or raise {@link IllegalArgumentException} if the value cannot be * there is no value, or raise {@link IllegalArgumentException} if the value cannot be
...@@ -823,8 +816,6 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable ...@@ -823,8 +816,6 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
set(headerName, dateFormat.format(new Date(date))); set(headerName, dateFormat.format(new Date(date)));
} }
// Single string methods
/** /**
* Return the first header value for the given header name, if any. * Return the first header value for the given header name, if any.
* @param headerName the header name * @param headerName the header name
...@@ -885,6 +876,7 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable ...@@ -885,6 +876,7 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
return singleValueMap; return singleValueMap;
} }
// Map implementation // Map implementation
@Override @Override
...@@ -970,4 +962,12 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable ...@@ -970,4 +962,12 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
return this.headers.toString(); return this.headers.toString();
} }
/**
* Return a {@code HttpHeaders} object that can only be read, not written to.
*/
public static HttpHeaders readOnlyHttpHeaders(HttpHeaders headers) {
return new HttpHeaders(headers, true);
}
} }
...@@ -1282,7 +1282,7 @@ public class DispatcherServlet extends FrameworkServlet { ...@@ -1282,7 +1282,7 @@ public class DispatcherServlet extends FrameworkServlet {
} }
private void triggerAfterCompletionWithError(HttpServletRequest request, HttpServletResponse response, private void triggerAfterCompletionWithError(HttpServletRequest request, HttpServletResponse response,
HandlerExecutionChain mappedHandler, Error error) throws Exception, ServletException { HandlerExecutionChain mappedHandler, Error error) throws Exception {
ServletException ex = new NestedServletException("Handler processing failed", error); ServletException ex = new NestedServletException("Handler processing failed", error);
if (mappedHandler != null) { if (mappedHandler != null) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册