@ -1,11 +1,11 @@
@@ -1,11 +1,11 @@
/ *
* Copyright 2002 - 2014 the original author or authors .
* Copyright 2002 - 2015 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 .
* You may obtain a copy of the License at
*
* http : //www.apache.org/licenses/LICENSE-2.0
* http : //www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing , software
* distributed under the License is distributed on an "AS IS" BASIS ,
@ -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 .
*
* < 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 >
* < 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 >
@ -134,18 +135,19 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
@@ -134,18 +135,19 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
return new HttpHeaders ( headers , true ) ;
}
/ * *
* Set the list of acceptable { @linkplain MediaType media types } , as specified by the { @code Accept } header .
* @param acceptableMediaTypes the acceptable media types
* Set the list of acceptable { @linkplain MediaType media types } ,
* as specified by the { @code Accept } header .
* /
public void setAccept ( List < MediaType > acceptableMediaTypes ) {
set ( ACCEPT , MediaType . toString ( acceptableMediaTypes ) ) ;
}
/ * *
* Return the list of acceptable { @linkplain MediaType media types } , as specified by the { @code Accept } header .
* Return the list of acceptable { @linkplain MediaType media types } ,
* as specified by the { @code Accept } header .
* < p > Returns an empty list when the acceptable media types are unspecified .
* @return the acceptable media types
* /
public List < MediaType > getAccept ( ) {
String value = getFirst ( ACCEPT ) ;
@ -164,8 +166,8 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
@@ -164,8 +166,8 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
}
/ * *
* Set the list of acceptable { @linkplain Charset charsets } , as specified by the { @code Accept - Charset } header .
* @param acceptableCharsets the acceptable charsets
* Set the list of acceptable { @linkplain Charset charsets } ,
* as specified by the { @code Accept - Charset } header .
* /
public void setAcceptCharset ( List < Charset > acceptableCharsets ) {
StringBuilder builder = new StringBuilder ( ) ;
@ -180,9 +182,8 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
@@ -180,9 +182,8 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
}
/ * *
* Return the list of acceptable { @linkplain Charset charsets } , as specified by the { @code Accept - Charset }
* header .
* @return the acceptable charsets
* Return the list of acceptable { @linkplain Charset charsets } ,
* as specified by the { @code Accept - Charset } header .
* /
public List < Charset > getAcceptCharset ( ) {
List < Charset > result = new ArrayList < Charset > ( ) ;
@ -207,27 +208,27 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
@@ -207,27 +208,27 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
}
/ * *
* Set the set of allowed { @link HttpMethod HTTP methods } , as specified by the { @code Allow } header .
* @param allowedMethods the allowed methods
* Set the set of allowed { @link HttpMethod HTTP methods } ,
* as specified by the { @code Allow } header .
* /
public void setAllow ( Set < HttpMethod > allowedMethods ) {
set ( ALLOW , StringUtils . collectionToCommaDelimitedString ( allowedMethods ) ) ;
}
/ * *
* Return the set of allowed { @link HttpMethod HTTP methods } , as specified by the { @code Allow } header .
* Return the set of allowed { @link HttpMethod HTTP methods } ,
* as specified by the { @code Allow } header .
* < p > Returns an empty set when the allowed methods are unspecified .
* @return the allowed methods
* /
public Set < HttpMethod > getAllow ( ) {
String value = getFirst ( ALLOW ) ;
if ( ! StringUtils . isEmpty ( value ) ) {
List < HttpMethod > allowedMethod = new Array List< HttpMethod > ( 5 ) ;
List < HttpMethod > result = new Linked List< HttpMethod > ( ) ;
String [ ] tokens = value . split ( ",\\s*" ) ;
for ( String token : tokens ) {
allowedMethod . add ( HttpMethod . valueOf ( token ) ) ;
result . add ( HttpMethod . valueOf ( token ) ) ;
}
return EnumSet . copyOf ( allowedMethod ) ;
return EnumSet . copyOf ( result ) ;
}
else {
return EnumSet . noneOf ( HttpMethod . class ) ;
@ -235,25 +236,24 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
@@ -235,25 +236,24 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
}
/ * *
* Sets the ( new ) value of the { @code Cache - Control } header .
* @param cacheControl the value of the header
* Set the ( new ) value of the { @code Cache - Control } header .
* /
public void setCacheControl ( String cacheControl ) {
set ( CACHE_CONTROL , cacheControl ) ;
}
/ * *
* Returns the value of the { @code Cache - Control } header .
* @return the value of the header
* Return the value of the { @code Cache - Control } header .
* /
public String getCacheControl ( ) {
return getFirst ( CACHE_CONTROL ) ;
}
/ * *
* Sets the ( new ) value of the { @code Content - Disposition } header for { @code form - data } .
* Set the ( new ) value of the { @code Content - Disposition } header
* for { @code form - data } .
* @param name the control name
* @param filename the filename , may be { @code null }
* @param filename the filename ( may be { @code null } )
* /
public void setContentDispositionFormData ( String name , String filename ) {
Assert . notNull ( name , "'name' must not be null" ) ;
@ -267,17 +267,17 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
@@ -267,17 +267,17 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
}
/ * *
* Set the length of the body in bytes , as specified by the { @code Content - Length } header .
* @param contentLength the content length
* Set the length of the body in bytes , as specified by the
* { @code Content - Length } header .
* /
public void setContentLength ( long contentLength ) {
set ( CONTENT_LENGTH , Long . toString ( contentLength ) ) ;
}
/ * *
* Return the length of the body in bytes , as specified by the { @code Content - Length } header .
* Return the length of the body in bytes , as specified by the
* { @code Content - Length } header .
* < p > Returns - 1 when the content - length is unknown .
* @return the content length
* /
public long getContentLength ( ) {
String value = getFirst ( CONTENT_LENGTH ) ;
@ -285,8 +285,8 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
@@ -285,8 +285,8 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
}
/ * *
* Set the { @linkplain MediaType media type } of the body , as specified by the { @code Content - Type } header .
* @param mediaType the media type
* Set the { @linkplain MediaType media type } of the body ,
* as specified by the { @code Content - Type } header .
* /
public void setContentType ( MediaType mediaType ) {
Assert . isTrue ( ! mediaType . isWildcardType ( ) , "'Content-Type' cannot contain wildcard type '*'" ) ;
@ -295,9 +295,9 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
@@ -295,9 +295,9 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
}
/ * *
* Return the { @linkplain MediaType media type } of the body , as specified by the { @code Content - Type } header .
* Return the { @linkplain MediaType media type } of the body , as specified
* by the { @code Content - Type } header .
* < p > Returns { @code null } when the content - type is unknown .
* @return the content type
* /
public MediaType getContentType ( ) {
String value = getFirst ( CONTENT_TYPE ) ;
@ -305,18 +305,20 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
@@ -305,18 +305,20 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
}
/ * *
* Sets the date and time at which the message was created , as specified by the { @code Date } header .
* < p > The date should be specified as the number of milliseconds since January 1 , 1970 GMT .
* @param date the date
* Set the date and time at which the message was created , as specified
* by the { @code Date } header .
* < p > The date should be specified as the number of milliseconds since
* January 1 , 1970 GMT .
* /
public void setDate ( long date ) {
setDate ( DATE , date ) ;
}
/ * *
* Returns the date and time at which the message was created , as specified by the { @code Date } header .
* < p > The date is returned as the number of milliseconds since January 1 , 1970 GMT . Returns - 1 when the date is unknown .
* @return the creation date / time
* Return the date and time at which the message was created , as specified
* by the { @code Date } header .
* < p > The date is returned as the number of milliseconds since
* January 1 , 1970 GMT . Returns - 1 when the date is unknown .
* @throws IllegalArgumentException if the value can ' t be converted to a date
* /
public long getDate ( ) {
@ -324,41 +326,39 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
@@ -324,41 +326,39 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
}
/ * *
* Sets the ( new ) entity tag of the body , as specified by the { @code ETag } header .
* @param eTag the new entity tag
* Set the ( new ) entity tag of the body , as specified by the { @code ETag } header .
* /
public void setETag ( String eTag ) {
if ( eTag ! = null ) {
Assert . isTrue ( eTag . startsWith ( "\"" ) | | eTag . startsWith ( "W/" ) , "Invalid eTag, does not start with W/ or \"" ) ;
Assert . isTrue ( eTag . startsWith ( "\"" ) | | eTag . startsWith ( "W/" ) ,
"Invalid eTag, does not start with W/ or \"" ) ;
Assert . isTrue ( eTag . endsWith ( "\"" ) , "Invalid eTag, does not end with \"" ) ;
}
set ( ETAG , eTag ) ;
}
/ * *
* Returns the entity tag of the body , as specified by the { @code ETag } header .
* @return the entity tag
* Return the entity tag of the body , as specified by the { @code ETag } header .
* /
public String getETag ( ) {
return getFirst ( ETAG ) ;
}
/ * *
* Sets the date and time at which the message is no longer valid , as specified by the { @code Expires } header .
* < p > The date should be specified as the number of milliseconds since January 1 , 1970 GMT .
* @param expires the new expires header value
* Set the date and time at which the message is no longer valid ,
* as specified by the { @code Expires } header .
* < p > The date should be specified as the number of milliseconds since
* January 1 , 1970 GMT .
* /
public void setExpires ( long expires ) {
setDate ( EXPIRES , expires ) ;
}
/ * *
* Returns the date and time at which the message is no longer valid , as specified by
* the { @code Expires } header .
* < p > The date is returned as the number of milliseconds since January 1 , 1970 GMT .
* Returns - 1 when the date is unknown .
*
* @return the expires value
* Return the date and time at which the message is no longer valid ,
* as specified by the { @code Expires } header .
* < p > The date is returned as the number of milliseconds since
* January 1 , 1970 GMT . Returns - 1 when the date is unknown .
* /
public long getExpires ( ) {
try {
@ -370,18 +370,18 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
@@ -370,18 +370,18 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
}
/ * *
* Sets the ( new ) value of the { @code If - Modified - Since } header .
* < p > The date should be specified as the number of milliseconds since January 1 , 1970 GMT .
* @param ifModifiedSince the new value of the header
* Set the ( new ) value of the { @code If - Modified - Since } header .
* < p > The date should be specified as the number of milliseconds since
* January 1 , 1970 GMT .
* /
public void setIfModifiedSince ( long ifModifiedSince ) {
setDate ( IF_MODIFIED_SINCE , ifModifiedSince ) ;
}
/ * *
* Returns the value of the { @code IfModifiedSince } header .
* < p > The date is returned as the number of milliseconds since January 1 , 1970 GMT . Returns - 1 when the date is unknown .
* @return the header value
* Return the value of the { @code IfModifiedSince } header .
* < p > The date is returned as the number of milliseconds since
* January 1 , 1970 GMT . Returns - 1 when the date is unknown .
* @deprecated use { @link # getIfModifiedSince ( ) }
* /
@Deprecated
@ -390,25 +390,23 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
@@ -390,25 +390,23 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
}
/ * *
* Returns the value of the { @code If - Modified - Since } header .
* < p > The date is returned as the number of milliseconds since January 1 , 1970 GMT . Returns - 1 when the date is unknown .
* @return the header value
* Return the value of the { @code If - Modified - Since } header .
* < p > The date is returned as the number of milliseconds since
* January 1 , 1970 GMT . Returns - 1 when the date is unknown .
* /
public long getIfModifiedSince ( ) {
return getFirstDate ( IF_MODIFIED_SINCE ) ;
}
/ * *
* Sets the ( new ) value of the { @code If - None - Match } header .
* @param ifNoneMatch the new value of the header
* Set the ( new ) value of the { @code If - None - Match } header .
* /
public void setIfNoneMatch ( String ifNoneMatch ) {
set ( IF_NONE_MATCH , ifNoneMatch ) ;
}
/ * *
* Sets the ( new ) values of the { @code If - None - Match } header .
* @param ifNoneMatchList the new value of the header
* Set the ( new ) values of the { @code If - None - Match } header .
* /
public void setIfNoneMatch ( List < String > ifNoneMatchList ) {
StringBuilder builder = new StringBuilder ( ) ;
@ -423,8 +421,7 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
@@ -423,8 +421,7 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
}
/ * *
* Returns the value of the { @code If - None - Match } header .
* @return the header value
* Return the value of the { @code If - None - Match } header .
* /
public List < String > getIfNoneMatch ( ) {
List < String > result = new ArrayList < String > ( ) ;
@ -439,35 +436,37 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
@@ -439,35 +436,37 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
}
/ * *
* Sets the time the resource was last changed , as specified by the { @code Last - Modified } header .
* < p > The date should be specified as the number of milliseconds since January 1 , 1970 GMT .
* @param lastModified the last modified date
* Set the time the resource was last changed , as specified by the
* { @code Last - Modified } header .
* < p > The date should be specified as the number of milliseconds since
* January 1 , 1970 GMT .
* /
public void setLastModified ( long lastModified ) {
setDate ( LAST_MODIFIED , lastModified ) ;
}
/ * *
* Returns the time the resource was last changed , as specified by the { @code Last - Modified } header .
* < p > The date is returned as the number of milliseconds since January 1 , 1970 GMT . Returns - 1 when the date is unknown .
* @return the last modified date
* Return the time the resource was last changed , as specified by the
* { @code Last - Modified } header .
* < p > The date is returned as the number of milliseconds since
* January 1 , 1970 GMT . Returns - 1 when the date is unknown .
* /
public long getLastModified ( ) {
return getFirstDate ( LAST_MODIFIED ) ;
}
/ * *
* Set the ( new ) location of a resource , as specified by the { @code Location } header .
* @param location the location
* Set the ( new ) location of a resource ,
* as specified by the { @code Location } header .
* /
public void setLocation ( URI location ) {
set ( LOCATION , location . toASCIIString ( ) ) ;
}
/ * *
* Return the ( new ) location of a resource , as specified by the { @code Location } header .
* Return the ( new ) location of a resource
* as specified by the { @code Location } header .
* < p > Returns { @code null } when the location is unknown .
* @return the location
* /
public URI getLocation ( ) {
String value = getFirst ( LOCATION ) ;
@ -475,16 +474,14 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
@@ -475,16 +474,14 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
}
/ * *
* Sets the ( new ) value of the { @code Pragma } header .
* @param pragma the value of the header
* Set the ( new ) value of the { @code Pragma } header .
* /
public void setPragma ( String pragma ) {
set ( PRAGMA , pragma ) ;
}
/ * *
* Returns the value of the { @code Pragma } header .
* @return the value of the header
* Return the value of the { @code Pragma } header .
* /
public String getPragma ( ) {
return getFirst ( PRAGMA ) ;
@ -493,9 +490,9 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
@@ -493,9 +490,9 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
// Date methods
/ * *
* 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
* parsed as a date .
* 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 parsed as a date .
* /
public long getFirstDate ( String headerName ) {
String headerValue = getFirst ( headerName ) ;
@ -508,7 +505,7 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
@@ -508,7 +505,7 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
try {
return simpleDateFormat . parse ( headerValue ) . getTime ( ) ;
}
catch ( ParseException e ) {
catch ( ParseException ex ) {
// ignore
}
}
@ -532,23 +529,23 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
@@ -532,23 +529,23 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
/ * *
* Return the first header value for the given header name , if any .
* @param headerName the header name
* @return the first header value ; or { @code null }
* @return the first header value , or { @code null } if none
* /
public String getFirst ( String headerName ) {
List < String > headerValues = headers . get ( headerName ) ;
return headerValues ! = null ? headerValues . get ( 0 ) : null ;
List < String > headerValues = this . headers . get ( headerName ) ;
return ( headerValues ! = null ? headerValues . get ( 0 ) : null ) ;
}
/ * *
* Add the given , single header value under the given name .
* @param headerName the header name
* @param headerName the header name
* @param headerValue the header value
* @throws UnsupportedOperationException if adding headers is not supported
* @see # put ( String , List )
* @see # set ( String , String )
* /
public void add ( String headerName , String headerValue ) {
List < String > headerValues = headers . get ( headerName ) ;
List < String > headerValues = this . headers . get ( headerName ) ;
if ( headerValues = = null ) {
headerValues = new LinkedList < String > ( ) ;
this . headers . put ( headerName , headerValues ) ;
@ -558,7 +555,7 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
@@ -558,7 +555,7 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
/ * *
* Set the given , single header value under the given name .
* @param headerName the header name
* @param headerName the header name
* @param headerValue the header value
* @throws UnsupportedOperationException if adding headers is not supported
* @see # put ( String , List )
@ -567,7 +564,7 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
@@ -567,7 +564,7 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
public void set ( String headerName , String headerValue ) {
List < String > headerValues = new LinkedList < String > ( ) ;
headerValues . add ( headerValue ) ;
headers . put ( headerName , headerValues ) ;
this . headers . put ( headerName , headerValues ) ;
}
public void setAll ( Map < String , String > values ) {
@ -578,7 +575,7 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
@@ -578,7 +575,7 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
public Map < String , String > toSingleValueMap ( ) {
LinkedHashMap < String , String > singleValueMap = new LinkedHashMap < String , String > ( this . headers . size ( ) ) ;
for ( Entry < String , List < String > > entry : headers . entrySet ( ) ) {
for ( Entry < String , List < String > > entry : this . headers . entrySet ( ) ) {
singleValueMap . put ( entry . getKey ( ) , entry . getValue ( ) . get ( 0 ) ) ;
}
return singleValueMap ;
@ -614,8 +611,8 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
@@ -614,8 +611,8 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
return this . headers . remove ( key ) ;
}
public void putAll ( Map < ? extends String , ? extends List < String > > m ) {
this . headers . putAll ( m ) ;
public void putAll ( Map < ? extends String , ? extends List < String > > map ) {
this . headers . putAll ( map ) ;
}
public void clear ( ) {