Class HttpHeaders
- java.lang.Object
-
- java.util.AbstractMap<String,Object>
-
- com.google.api.client.util.GenericData
-
- com.google.api.client.http.HttpHeaders
-
public class HttpHeaders extends GenericData
Stores HTTP headers used in an HTTP request or response, as defined in Header Field Definitions.null
is not allowed as a name or value of a header. Names are case-insensitive.Implementation is not thread-safe.
- Since:
- 1.0
- Author:
- Yaniv Inbar
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.google.api.client.util.GenericData
GenericData.Flags
-
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,V extends Object>
-
-
Constructor Summary
Constructors Constructor Description HttpHeaders()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description HttpHeaders
clone()
Makes a "deep" clone of the generic data, in which the clone is completely independent of the original.void
fromHttpHeaders(HttpHeaders headers)
Puts all headers of theHttpHeaders
object into thisHttpHeaders
object.void
fromHttpResponse(LowLevelHttpResponse response, StringBuilder logger)
Puts all headers of theLowLevelHttpResponse
into thisHttpHeaders
object.String
getAccept()
Returns the first"Accept"
header ornull
for none.String
getAcceptEncoding()
Returns the first"Accept-Encoding"
header ornull
for none.Long
getAge()
Returns the first"Age"
header ornull
for none.String
getAuthenticate()
Returns the first"WWW-Authenticate"
header ornull
for none.List<String>
getAuthenticateAsList()
Returns all"WWW-Authenticate"
headers ornull
for none.String
getAuthorization()
Returns the first"Authorization"
header ornull
for none.List<String>
getAuthorizationAsList()
Returns all"Authorization"
headers ornull
for none.String
getCacheControl()
Returns the first"Cache-Control"
header ornull
for none.String
getContentEncoding()
Returns the first"Content-Encoding"
header ornull
for none.Long
getContentLength()
Returns the first"Content-Length"
header ornull
for none.String
getContentMD5()
Returns the first"Content-MD5"
header ornull
for none.String
getContentRange()
Returns the first"Content-Range"
header ornull
for none.String
getContentType()
Returns the first"Content-Type"
header ornull
for none.String
getCookie()
Returns the first"Cookie"
header ornull
for none.String
getDate()
Returns the first"Date"
header ornull
for none.String
getETag()
Returns the first"ETag"
header ornull
for none.String
getExpires()
Returns the first"Expires"
header ornull
for none.String
getFirstHeaderStringValue(String name)
Returns the first header string value for the given header name.List<String>
getHeaderStringValues(String name)
Returns an unmodifiable list of the header string values for the given header name.String
getIfMatch()
Returns the first"If-Match"
header ornull
for none.String
getIfModifiedSince()
Returns the first"If-Modified-Since"
header ornull
for none.String
getIfNoneMatch()
Returns the first"If-None-Match"
header ornull
for none.String
getIfRange()
Returns the first"If-Range"
header ornull
for none.String
getIfUnmodifiedSince()
Returns the first"If-Unmodified-Since"
header ornull
for none.String
getLastModified()
Returns the first"Last-Modified"
header ornull
for none.String
getLocation()
Returns the first"Location"
header ornull
for none.String
getMimeVersion()
Returns the first"MIME-Version"
header ornull
for none.String
getRange()
Returns the first"Range"
header ornull
for none.String
getRetryAfter()
Returns the first"Retry-After"
header ornull
for none.String
getUserAgent()
Returns the first"User-Agent"
header ornull
for none.static void
serializeHeadersForMultipartRequests(HttpHeaders headers, StringBuilder logbuf, Logger logger, Writer writer)
Serializes headers to anWriter
for Multi-part requests.HttpHeaders
set(String fieldName, Object value)
Sets the given field value (may benull
) for the given field name.HttpHeaders
setAccept(String accept)
Sets the"Accept"
header ornull
for none.HttpHeaders
setAcceptEncoding(String acceptEncoding)
Sets the"Accept-Encoding"
header ornull
for none.HttpHeaders
setAge(Long age)
Sets the"Age"
header ornull
for none.HttpHeaders
setAuthenticate(String authenticate)
Sets the"WWW-Authenticate"
header ornull
for none.HttpHeaders
setAuthorization(String authorization)
Sets the"Authorization"
header ornull
for none.HttpHeaders
setAuthorization(List<String> authorization)
Sets the"Authorization"
header ornull
for none.HttpHeaders
setBasicAuthentication(String username, String password)
Sets theauthorization
header as specified in Basic Authentication Scheme.HttpHeaders
setCacheControl(String cacheControl)
Sets the"Cache-Control"
header ornull
for none.HttpHeaders
setContentEncoding(String contentEncoding)
Sets the"Content-Encoding"
header ornull
for none.HttpHeaders
setContentLength(Long contentLength)
Sets the"Content-Length"
header ornull
for none.HttpHeaders
setContentMD5(String contentMD5)
Sets the"Content-MD5"
header ornull
for none.HttpHeaders
setContentRange(String contentRange)
Sets the"Content-Range"
header ornull
for none.HttpHeaders
setContentType(String contentType)
Sets the"Content-Type"
header ornull
for none.HttpHeaders
setCookie(String cookie)
Sets the"Cookie"
header ornull
for none.HttpHeaders
setDate(String date)
Sets the"Date"
header ornull
for none.HttpHeaders
setETag(String etag)
Sets the"ETag"
header ornull
for none.HttpHeaders
setExpires(String expires)
Sets the"Expires"
header ornull
for none.HttpHeaders
setIfMatch(String ifMatch)
Sets the"If-Match"
header ornull
for none.HttpHeaders
setIfModifiedSince(String ifModifiedSince)
Sets the"If-Modified-Since"
header ornull
for none.HttpHeaders
setIfNoneMatch(String ifNoneMatch)
Sets the"If-None-Match"
header ornull
for none.HttpHeaders
setIfRange(String ifRange)
Sets the"If-Range"
header ornull
for none.HttpHeaders
setIfUnmodifiedSince(String ifUnmodifiedSince)
Sets the"If-Unmodified-Since"
header ornull
for none.HttpHeaders
setLastModified(String lastModified)
Sets the"Last-Modified"
header ornull
for none.HttpHeaders
setLocation(String location)
Sets the"Location"
header ornull
for none.HttpHeaders
setMimeVersion(String mimeVersion)
Sets the"MIME-Version"
header ornull
for none.HttpHeaders
setRange(String range)
Sets the"Range"
header ornull
for none.HttpHeaders
setRetryAfter(String retryAfter)
Sets the"Retry-After"
header ornull
for none.HttpHeaders
setUserAgent(String userAgent)
Sets the"User-Agent"
header ornull
for none.-
Methods inherited from class com.google.api.client.util.GenericData
entrySet, get, getClassInfo, getUnknownKeys, put, putAll, remove, setUnknownKeys
-
Methods inherited from class java.util.AbstractMap
clear, containsKey, containsValue, equals, hashCode, isEmpty, keySet, size, toString, values
-
-
-
-
Method Detail
-
clone
public HttpHeaders clone()
Description copied from class:GenericData
Makes a "deep" clone of the generic data, in which the clone is completely independent of the original.- Overrides:
clone
in classGenericData
-
set
public HttpHeaders set(String fieldName, Object value)
Description copied from class:GenericData
Sets the given field value (may benull
) for the given field name. Any existing value for the field will be overwritten. It may be more slightly more efficient thanGenericData.put(String, Object)
because it avoids accessing the field's original value.Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
- Overrides:
set
in classGenericData
-
getAccept
public final String getAccept()
Returns the first"Accept"
header ornull
for none.- Since:
- 1.5
-
setAccept
public HttpHeaders setAccept(String accept)
Sets the"Accept"
header ornull
for none.Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
- Since:
- 1.5
-
getAcceptEncoding
public final String getAcceptEncoding()
Returns the first"Accept-Encoding"
header ornull
for none.- Since:
- 1.5
-
setAcceptEncoding
public HttpHeaders setAcceptEncoding(String acceptEncoding)
Sets the"Accept-Encoding"
header ornull
for none.By default, this is
"gzip"
.- Since:
- 1.5
-
getAuthorization
public final String getAuthorization()
Returns the first"Authorization"
header ornull
for none.- Since:
- 1.5
-
getAuthorizationAsList
public final List<String> getAuthorizationAsList()
Returns all"Authorization"
headers ornull
for none.- Since:
- 1.13
-
setAuthorization
public HttpHeaders setAuthorization(String authorization)
Sets the"Authorization"
header ornull
for none.Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
- Since:
- 1.5
-
setAuthorization
public HttpHeaders setAuthorization(List<String> authorization)
Sets the"Authorization"
header ornull
for none.Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
- Since:
- 1.13
-
getCacheControl
public final String getCacheControl()
Returns the first"Cache-Control"
header ornull
for none.- Since:
- 1.5
-
setCacheControl
public HttpHeaders setCacheControl(String cacheControl)
Sets the"Cache-Control"
header ornull
for none.Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
- Since:
- 1.5
-
getContentEncoding
public final String getContentEncoding()
Returns the first"Content-Encoding"
header ornull
for none.- Since:
- 1.5
-
setContentEncoding
public HttpHeaders setContentEncoding(String contentEncoding)
Sets the"Content-Encoding"
header ornull
for none.Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
- Since:
- 1.5
-
getContentLength
public final Long getContentLength()
Returns the first"Content-Length"
header ornull
for none.- Since:
- 1.5
-
setContentLength
public HttpHeaders setContentLength(Long contentLength)
Sets the"Content-Length"
header ornull
for none.Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
- Since:
- 1.5
-
getContentMD5
public final String getContentMD5()
Returns the first"Content-MD5"
header ornull
for none.- Since:
- 1.5
-
setContentMD5
public HttpHeaders setContentMD5(String contentMD5)
Sets the"Content-MD5"
header ornull
for none.Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
- Since:
- 1.5
-
getContentRange
public final String getContentRange()
Returns the first"Content-Range"
header ornull
for none.- Since:
- 1.5
-
setContentRange
public HttpHeaders setContentRange(String contentRange)
Sets the"Content-Range"
header ornull
for none.Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
- Since:
- 1.5
-
getContentType
public final String getContentType()
Returns the first"Content-Type"
header ornull
for none.- Since:
- 1.5
-
setContentType
public HttpHeaders setContentType(String contentType)
Sets the"Content-Type"
header ornull
for none.Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
- Since:
- 1.5
-
getCookie
public final String getCookie()
- Since:
- 1.6
-
setCookie
public HttpHeaders setCookie(String cookie)
Sets the"Cookie"
header ornull
for none.Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
- Since:
- 1.6
-
getDate
public final String getDate()
Returns the first"Date"
header ornull
for none.- Since:
- 1.5
-
setDate
public HttpHeaders setDate(String date)
Sets the"Date"
header ornull
for none.Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
- Since:
- 1.5
-
getETag
public final String getETag()
Returns the first"ETag"
header ornull
for none.- Since:
- 1.5
-
setETag
public HttpHeaders setETag(String etag)
Sets the"ETag"
header ornull
for none.Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
- Since:
- 1.5
-
getExpires
public final String getExpires()
Returns the first"Expires"
header ornull
for none.- Since:
- 1.5
-
setExpires
public HttpHeaders setExpires(String expires)
Sets the"Expires"
header ornull
for none.Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
- Since:
- 1.5
-
getIfModifiedSince
public final String getIfModifiedSince()
Returns the first"If-Modified-Since"
header ornull
for none.- Since:
- 1.5
-
setIfModifiedSince
public HttpHeaders setIfModifiedSince(String ifModifiedSince)
Sets the"If-Modified-Since"
header ornull
for none.Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
- Since:
- 1.5
-
getIfMatch
public final String getIfMatch()
Returns the first"If-Match"
header ornull
for none.- Since:
- 1.5
-
setIfMatch
public HttpHeaders setIfMatch(String ifMatch)
Sets the"If-Match"
header ornull
for none.Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
- Since:
- 1.5
-
getIfNoneMatch
public final String getIfNoneMatch()
Returns the first"If-None-Match"
header ornull
for none.- Since:
- 1.5
-
setIfNoneMatch
public HttpHeaders setIfNoneMatch(String ifNoneMatch)
Sets the"If-None-Match"
header ornull
for none.Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
- Since:
- 1.5
-
getIfUnmodifiedSince
public final String getIfUnmodifiedSince()
Returns the first"If-Unmodified-Since"
header ornull
for none.- Since:
- 1.5
-
setIfUnmodifiedSince
public HttpHeaders setIfUnmodifiedSince(String ifUnmodifiedSince)
Sets the"If-Unmodified-Since"
header ornull
for none.Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
- Since:
- 1.5
-
getIfRange
public final String getIfRange()
Returns the first"If-Range"
header ornull
for none.- Since:
- 1.14
-
setIfRange
public HttpHeaders setIfRange(String ifRange)
Sets the"If-Range"
header ornull
for none.Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
- Since:
- 1.14
-
getLastModified
public final String getLastModified()
Returns the first"Last-Modified"
header ornull
for none.- Since:
- 1.5
-
setLastModified
public HttpHeaders setLastModified(String lastModified)
Sets the"Last-Modified"
header ornull
for none.Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
- Since:
- 1.5
-
getLocation
public final String getLocation()
Returns the first"Location"
header ornull
for none.- Since:
- 1.5
-
setLocation
public HttpHeaders setLocation(String location)
Sets the"Location"
header ornull
for none.Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
- Since:
- 1.5
-
getMimeVersion
public final String getMimeVersion()
Returns the first"MIME-Version"
header ornull
for none.- Since:
- 1.5
-
setMimeVersion
public HttpHeaders setMimeVersion(String mimeVersion)
Sets the"MIME-Version"
header ornull
for none.Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
- Since:
- 1.5
-
getRange
public final String getRange()
Returns the first"Range"
header ornull
for none.- Since:
- 1.5
-
setRange
public HttpHeaders setRange(String range)
Sets the"Range"
header ornull
for none.Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
- Since:
- 1.5
-
getRetryAfter
public final String getRetryAfter()
Returns the first"Retry-After"
header ornull
for none.- Since:
- 1.5
-
setRetryAfter
public HttpHeaders setRetryAfter(String retryAfter)
Sets the"Retry-After"
header ornull
for none.Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
- Since:
- 1.5
-
getUserAgent
public final String getUserAgent()
Returns the first"User-Agent"
header ornull
for none.- Since:
- 1.5
-
setUserAgent
public HttpHeaders setUserAgent(String userAgent)
Sets the"User-Agent"
header ornull
for none.Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
- Since:
- 1.5
-
getAuthenticate
public final String getAuthenticate()
Returns the first"WWW-Authenticate"
header ornull
for none.- Since:
- 1.5
-
getAuthenticateAsList
public final List<String> getAuthenticateAsList()
Returns all"WWW-Authenticate"
headers ornull
for none.- Since:
- 1.16
-
setAuthenticate
public HttpHeaders setAuthenticate(String authenticate)
Sets the"WWW-Authenticate"
header ornull
for none.Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
- Since:
- 1.5
-
getAge
public final Long getAge()
Returns the first"Age"
header ornull
for none.- Since:
- 1.14
-
setAge
public HttpHeaders setAge(Long age)
Sets the"Age"
header ornull
for none.Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
- Since:
- 1.14
-
setBasicAuthentication
public HttpHeaders setBasicAuthentication(String username, String password)
Sets theauthorization
header as specified in Basic Authentication Scheme.Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
- Since:
- 1.2
-
serializeHeadersForMultipartRequests
public static void serializeHeadersForMultipartRequests(HttpHeaders headers, StringBuilder logbuf, Logger logger, Writer writer) throws IOException
Serializes headers to anWriter
for Multi-part requests.- Parameters:
headers
- HTTP headerslogbuf
- log buffer ornull
for nonelogger
- logger ornull
for none. Logger must be specified if log buffer is specifiedwriter
- Writer where HTTP headers will be serialized to ornull
for none- Throws:
IOException
- Since:
- 1.9
-
fromHttpResponse
public final void fromHttpResponse(LowLevelHttpResponse response, StringBuilder logger) throws IOException
Puts all headers of theLowLevelHttpResponse
into thisHttpHeaders
object.- Parameters:
response
- Response from which the headers are copiedlogger
-StringBuilder
to which logging output is added ornull
to disable logging- Throws:
IOException
- Since:
- 1.10
-
getFirstHeaderStringValue
public String getFirstHeaderStringValue(String name)
Returns the first header string value for the given header name.- Parameters:
name
- header name (may be any case)- Returns:
- first header string value or
null
if not found - Since:
- 1.13
-
getHeaderStringValues
public List<String> getHeaderStringValues(String name)
Returns an unmodifiable list of the header string values for the given header name.- Parameters:
name
- header name (may be any case)- Returns:
- header string values or empty if not found
- Since:
- 1.13
-
fromHttpHeaders
public final void fromHttpHeaders(HttpHeaders headers)
Puts all headers of theHttpHeaders
object into thisHttpHeaders
object.- Parameters:
headers
-HttpHeaders
from where the headers are taken- Since:
- 1.10
-
-