public class

HttpHeaders

extends Object
implements MultiValueMap<K, V>
java.lang.Object
   ↳ org.springframework.http.HttpHeaders

Class Overview

Represents HTTP request and response headers, mapping string header names to list of string values.

In addition to the normal methods defined by Map, this class offers the following convenience methods:

Inspired by com.sun.net.httpserver.Headers.

Summary

Public Constructors
HttpHeaders()
Constructs a new, empty instance of the HttpHeaders object.
Public Methods
void add(String headerName, String headerValue)
Add the given, single header value under the given name.
void clear()
boolean containsKey(Object key)
boolean containsValue(Object value)
Set<Entry<StringList<String>>> entrySet()
boolean equals(Object other)
List<String> get(Object key)
List<MediaType> getAccept()
Return the list of acceptable media types, as specified by the Accept header.
List<Charset> getAcceptCharset()
Return the list of acceptable charsets, as specified by the Accept-Charset header.
Set<HttpMethod> getAllow()
Return the set of allowed HTTP methods, as specified by the Allow header.
String getCacheControl()
Returns the value of the Cache-Control header.
long getContentLength()
Return the length of the body in bytes, as specified by the Content-Length header.
MediaType getContentType()
Return the media type of the body, as specified by the Content-Type header.
long getDate()
Returns the date and time at which the message was created, as specified by the Date header.
String getETag()
Returns the entity tag of the body, as specified by the ETag header.
long getExpires()
Returns the date and time at which the message is no longer valid, as specified by the Expires header.
String getFirst(String headerName)
Return the first header value for the given header name, if any.
List<String> getIfNoneMatch()
Returns the value of the If-None-Match header.
long getIfNotModifiedSince()
Returns the value of the IfModifiedSince header.
long getLastModified()
Returns the time the resource was last changed, as specified by the Last-Modified header.
URI getLocation()
Return the (new) location of a resource, as specified by the Location header.
String getPragma()
Returns the value of the Pragma header.
int hashCode()
boolean isEmpty()
Set<String> keySet()
List<String> put(String key, List<String> value)
void putAll(Map<? extends String, ? extends List<String>> m)
static HttpHeaders readOnlyHttpHeaders(HttpHeaders headers)
Returns HttpHeaders object that can only be read, not written to.
List<String> remove(Object key)
void set(String headerName, String headerValue)
Set the given, single header value under the given name.
void setAccept(List<MediaType> acceptableMediaTypes)
Set the list of acceptable media types, as specified by the Accept header.
void setAcceptCharset(List<Charset> acceptableCharsets)
Set the list of acceptable charsets, as specified by the Accept-Charset header.
void setAll(Map<StringString> values)
void setAllow(Set<HttpMethod> allowedMethods)
Set the set of allowed HTTP methods, as specified by the Allow header.
void setCacheControl(String cacheControl)
Sets the (new) value of the Cache-Control header.
void setContentDispositionFormData(String name, String filename)
Sets the (new) value of the Content-Disposition header for form-data.
void setContentLength(long contentLength)
Set the length of the body in bytes, as specified by the Content-Length header.
void setContentType(MediaType mediaType)
Set the media type of the body, as specified by the Content-Type header.
void setDate(long date)
Sets the date and time at which the message was created, as specified by the Date header.
void setETag(String eTag)
Sets the (new) entity tag of the body, as specified by the ETag header.
void setExpires(long expires)
Sets the date and time at which the message is no longer valid, as specified by the Expires header.
void setIfModifiedSince(long ifModifiedSince)
Sets the (new) value of the If-Modified-Since header.
void setIfNoneMatch(String ifNoneMatch)
Sets the (new) value of the If-None-Match header.
void setIfNoneMatch(List<String> ifNoneMatchList)
Sets the (new) values of the If-None-Match header.
void setLastModified(long lastModified)
Sets the time the resource was last changed, as specified by the Last-Modified header.
void setLocation(URI location)
Set the (new) location of a resource, as specified by the Location header.
void setPragma(String pragma)
Sets the (new) value of the Pragma header.
int size()
Map<StringString> toSingleValueMap()
Returns the first values contained in this MultiValueMap.
String toString()
Collection<List<String>> values()
[Expand]
Inherited Methods
From class java.lang.Object
From interface java.util.Map
From interface org.springframework.util.MultiValueMap

Public Constructors

public HttpHeaders ()

Constructs a new, empty instance of the HttpHeaders object.

Public Methods

public void add (String headerName, String headerValue)

Add the given, single header value under the given name.

Parameters
headerName the header name
headerValue the header value
Throws
UnsupportedOperationException if adding headers is not supported

public void clear ()

public boolean containsKey (Object key)

public boolean containsValue (Object value)

public Set<Entry<StringList<String>>> entrySet ()

public boolean equals (Object other)

public List<String> get (Object key)

public List<MediaType> getAccept ()

Return the list of acceptable media types, as specified by the Accept header.

Returns an empty list when the acceptable media types are unspecified.

Returns
  • the acceptable media types

public List<Charset> getAcceptCharset ()

Return the list of acceptable charsets, as specified by the Accept-Charset header.

Returns
  • the acceptable charsets

public Set<HttpMethod> getAllow ()

Return the set of allowed HTTP methods, as specified by the Allow header.

Returns an empty set when the allowed methods are unspecified.

Returns
  • the allowed methods

public String getCacheControl ()

Returns the value of the Cache-Control header.

Returns
  • the value of the header

public long getContentLength ()

Return the length of the body in bytes, as specified by the Content-Length header.

Returns -1 when the content-length is unknown.

Returns
  • the content length

public MediaType getContentType ()

Return the media type of the body, as specified by the Content-Type header.

Returns null when the content-type is unknown.

Returns
  • the content type

public long getDate ()

Returns the date and time at which the message was created, as specified by the Date header.

The date is returned as the number of milliseconds since January 1, 1970 GMT. Returns -1 when the date is unknown.

Returns
  • the creation date/time
Throws
IllegalArgumentException if the value can't be converted to a date

public String getETag ()

Returns the entity tag of the body, as specified by the ETag header.

Returns
  • the entity tag

public long getExpires ()

Returns the date and time at which the message is no longer valid, as specified by the Expires header.

The date is returned as the number of milliseconds since January 1, 1970 GMT. Returns -1 when the date is unknown.

Returns
  • the expires value

public String getFirst (String headerName)

Return the first header value for the given header name, if any.

Parameters
headerName the header name
Returns
  • the first header value; or null

public List<String> getIfNoneMatch ()

Returns the value of the If-None-Match header.

Returns
  • the header value

public long getIfNotModifiedSince ()

Returns the value of the IfModifiedSince header.

The date is returned as the number of milliseconds since January 1, 1970 GMT. Returns -1 when the date is unknown.

Returns
  • the header value

public long getLastModified ()

Returns the time the resource was last changed, as specified by the Last-Modified header.

The date is returned as the number of milliseconds since January 1, 1970 GMT. Returns -1 when the date is unknown.

Returns
  • the last modified date

public URI getLocation ()

Return the (new) location of a resource, as specified by the Location header.

Returns null when the location is unknown.

Returns
  • the location

public String getPragma ()

Returns the value of the Pragma header.

Returns
  • the value of the header

public int hashCode ()

public boolean isEmpty ()

public Set<String> keySet ()

public List<String> put (String key, List<String> value)

public void putAll (Map<? extends String, ? extends List<String>> m)

public static HttpHeaders readOnlyHttpHeaders (HttpHeaders headers)

Returns HttpHeaders object that can only be read, not written to.

public List<String> remove (Object key)

public void set (String headerName, String headerValue)

Set the given, single header value under the given name.

Parameters
headerName the header name
headerValue the header value
Throws
UnsupportedOperationException if adding headers is not supported

public void setAccept (List<MediaType> acceptableMediaTypes)

Set the list of acceptable media types, as specified by the Accept header.

Parameters
acceptableMediaTypes the acceptable media types

public void setAcceptCharset (List<Charset> acceptableCharsets)

Set the list of acceptable charsets, as specified by the Accept-Charset header.

Parameters
acceptableCharsets the acceptable charsets

public void setAll (Map<StringString> values)

public void setAllow (Set<HttpMethod> allowedMethods)

Set the set of allowed HTTP methods, as specified by the Allow header.

Parameters
allowedMethods the allowed methods

public void setCacheControl (String cacheControl)

Sets the (new) value of the Cache-Control header.

Parameters
cacheControl the value of the header

public void setContentDispositionFormData (String name, String filename)

Sets the (new) value of the Content-Disposition header for form-data.

Parameters
name the control name
filename the filename, may be null

public void setContentLength (long contentLength)

Set the length of the body in bytes, as specified by the Content-Length header.

Parameters
contentLength the content length

public void setContentType (MediaType mediaType)

Set the media type of the body, as specified by the Content-Type header.

Parameters
mediaType the media type

public void setDate (long date)

Sets the date and time at which the message was created, as specified by the Date header.

The date should be specified as the number of milliseconds since January 1, 1970 GMT.

Parameters
date the date

public void setETag (String eTag)

Sets the (new) entity tag of the body, as specified by the ETag header.

Parameters
eTag the new entity tag

public void setExpires (long expires)

Sets the date and time at which the message is no longer valid, as specified by the Expires header.

The date should be specified as the number of milliseconds since January 1, 1970 GMT.

Parameters
expires the new expires header value

public void setIfModifiedSince (long ifModifiedSince)

Sets the (new) value of the If-Modified-Since header.

The date should be specified as the number of milliseconds since January 1, 1970 GMT.

Parameters
ifModifiedSince the new value of the header

public void setIfNoneMatch (String ifNoneMatch)

Sets the (new) value of the If-None-Match header.

Parameters
ifNoneMatch the new value of the header

public void setIfNoneMatch (List<String> ifNoneMatchList)

Sets the (new) values of the If-None-Match header.

Parameters
ifNoneMatchList the new value of the header

public void setLastModified (long lastModified)

Sets the time the resource was last changed, as specified by the Last-Modified header.

The date should be specified as the number of milliseconds since January 1, 1970 GMT.

Parameters
lastModified the last modified date

public void setLocation (URI location)

Set the (new) location of a resource, as specified by the Location header.

Parameters
location the location

public void setPragma (String pragma)

Sets the (new) value of the Pragma header.

Parameters
pragma the value of the header

public int size ()

public Map<StringString> toSingleValueMap ()

Returns the first values contained in this MultiValueMap.

Returns
  • a single value representation of this map

public String toString ()

public Collection<List<String>> values ()