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.nullis 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 HttpHeadersclone()Makes a "deep" clone of the generic data, in which the clone is completely independent of the original.voidfromHttpHeaders(HttpHeaders headers)Puts all headers of theHttpHeadersobject into thisHttpHeadersobject.voidfromHttpResponse(LowLevelHttpResponse response, StringBuilder logger)Puts all headers of theLowLevelHttpResponseinto thisHttpHeadersobject.StringgetAccept()Returns the first"Accept"header ornullfor none.StringgetAcceptEncoding()Returns the first"Accept-Encoding"header ornullfor none.LonggetAge()Returns the first"Age"header ornullfor none.StringgetAuthenticate()Returns the first"WWW-Authenticate"header ornullfor none.List<String>getAuthenticateAsList()Returns all"WWW-Authenticate"headers ornullfor none.StringgetAuthorization()Returns the first"Authorization"header ornullfor none.List<String>getAuthorizationAsList()Returns all"Authorization"headers ornullfor none.StringgetCacheControl()Returns the first"Cache-Control"header ornullfor none.StringgetContentEncoding()Returns the first"Content-Encoding"header ornullfor none.LonggetContentLength()Returns the first"Content-Length"header ornullfor none.StringgetContentMD5()Returns the first"Content-MD5"header ornullfor none.StringgetContentRange()Returns the first"Content-Range"header ornullfor none.StringgetContentType()Returns the first"Content-Type"header ornullfor none.StringgetCookie()Returns the first"Cookie"header ornullfor none.StringgetDate()Returns the first"Date"header ornullfor none.StringgetETag()Returns the first"ETag"header ornullfor none.StringgetExpires()Returns the first"Expires"header ornullfor none.StringgetFirstHeaderStringValue(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.StringgetIfMatch()Returns the first"If-Match"header ornullfor none.StringgetIfModifiedSince()Returns the first"If-Modified-Since"header ornullfor none.StringgetIfNoneMatch()Returns the first"If-None-Match"header ornullfor none.StringgetIfRange()Returns the first"If-Range"header ornullfor none.StringgetIfUnmodifiedSince()Returns the first"If-Unmodified-Since"header ornullfor none.StringgetLastModified()Returns the first"Last-Modified"header ornullfor none.StringgetLocation()Returns the first"Location"header ornullfor none.StringgetMimeVersion()Returns the first"MIME-Version"header ornullfor none.StringgetRange()Returns the first"Range"header ornullfor none.StringgetRetryAfter()Returns the first"Retry-After"header ornullfor none.StringgetUserAgent()Returns the first"User-Agent"header ornullfor none.static voidserializeHeadersForMultipartRequests(HttpHeaders headers, StringBuilder logbuf, Logger logger, Writer writer)Serializes headers to anWriterfor Multi-part requests.HttpHeadersset(String fieldName, Object value)Sets the given field value (may benull) for the given field name.HttpHeaderssetAccept(String accept)Sets the"Accept"header ornullfor none.HttpHeaderssetAcceptEncoding(String acceptEncoding)Sets the"Accept-Encoding"header ornullfor none.HttpHeaderssetAge(Long age)Sets the"Age"header ornullfor none.HttpHeaderssetAuthenticate(String authenticate)Sets the"WWW-Authenticate"header ornullfor none.HttpHeaderssetAuthorization(String authorization)Sets the"Authorization"header ornullfor none.HttpHeaderssetAuthorization(List<String> authorization)Sets the"Authorization"header ornullfor none.HttpHeaderssetBasicAuthentication(String username, String password)Sets theauthorizationheader as specified in Basic Authentication Scheme.HttpHeaderssetCacheControl(String cacheControl)Sets the"Cache-Control"header ornullfor none.HttpHeaderssetContentEncoding(String contentEncoding)Sets the"Content-Encoding"header ornullfor none.HttpHeaderssetContentLength(Long contentLength)Sets the"Content-Length"header ornullfor none.HttpHeaderssetContentMD5(String contentMD5)Sets the"Content-MD5"header ornullfor none.HttpHeaderssetContentRange(String contentRange)Sets the"Content-Range"header ornullfor none.HttpHeaderssetContentType(String contentType)Sets the"Content-Type"header ornullfor none.HttpHeaderssetCookie(String cookie)Sets the"Cookie"header ornullfor none.HttpHeaderssetDate(String date)Sets the"Date"header ornullfor none.HttpHeaderssetETag(String etag)Sets the"ETag"header ornullfor none.HttpHeaderssetExpires(String expires)Sets the"Expires"header ornullfor none.HttpHeaderssetIfMatch(String ifMatch)Sets the"If-Match"header ornullfor none.HttpHeaderssetIfModifiedSince(String ifModifiedSince)Sets the"If-Modified-Since"header ornullfor none.HttpHeaderssetIfNoneMatch(String ifNoneMatch)Sets the"If-None-Match"header ornullfor none.HttpHeaderssetIfRange(String ifRange)Sets the"If-Range"header ornullfor none.HttpHeaderssetIfUnmodifiedSince(String ifUnmodifiedSince)Sets the"If-Unmodified-Since"header ornullfor none.HttpHeaderssetLastModified(String lastModified)Sets the"Last-Modified"header ornullfor none.HttpHeaderssetLocation(String location)Sets the"Location"header ornullfor none.HttpHeaderssetMimeVersion(String mimeVersion)Sets the"MIME-Version"header ornullfor none.HttpHeaderssetRange(String range)Sets the"Range"header ornullfor none.HttpHeaderssetRetryAfter(String retryAfter)Sets the"Retry-After"header ornullfor none.HttpHeaderssetUserAgent(String userAgent)Sets the"User-Agent"header ornullfor 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:GenericDataMakes a "deep" clone of the generic data, in which the clone is completely independent of the original.- Overrides:
clonein classGenericData
-
set
public HttpHeaders set(String fieldName, Object value)
Description copied from class:GenericDataSets 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:
setin classGenericData
-
getAccept
public final String getAccept()
Returns the first"Accept"header ornullfor none.- Since:
- 1.5
-
setAccept
public HttpHeaders setAccept(String accept)
Sets the"Accept"header ornullfor 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 ornullfor none.- Since:
- 1.5
-
setAcceptEncoding
public HttpHeaders setAcceptEncoding(String acceptEncoding)
Sets the"Accept-Encoding"header ornullfor none.By default, this is
"gzip".- Since:
- 1.5
-
getAuthorization
public final String getAuthorization()
Returns the first"Authorization"header ornullfor none.- Since:
- 1.5
-
getAuthorizationAsList
public final List<String> getAuthorizationAsList()
Returns all"Authorization"headers ornullfor none.- Since:
- 1.13
-
setAuthorization
public HttpHeaders setAuthorization(String authorization)
Sets the"Authorization"header ornullfor 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 ornullfor 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 ornullfor none.- Since:
- 1.5
-
setCacheControl
public HttpHeaders setCacheControl(String cacheControl)
Sets the"Cache-Control"header ornullfor 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 ornullfor none.- Since:
- 1.5
-
setContentEncoding
public HttpHeaders setContentEncoding(String contentEncoding)
Sets the"Content-Encoding"header ornullfor 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 ornullfor none.- Since:
- 1.5
-
setContentLength
public HttpHeaders setContentLength(Long contentLength)
Sets the"Content-Length"header ornullfor 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 ornullfor none.- Since:
- 1.5
-
setContentMD5
public HttpHeaders setContentMD5(String contentMD5)
Sets the"Content-MD5"header ornullfor 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 ornullfor none.- Since:
- 1.5
-
setContentRange
public HttpHeaders setContentRange(String contentRange)
Sets the"Content-Range"header ornullfor 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 ornullfor none.- Since:
- 1.5
-
setContentType
public HttpHeaders setContentType(String contentType)
Sets the"Content-Type"header ornullfor 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 ornullfor 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 ornullfor none.- Since:
- 1.5
-
setDate
public HttpHeaders setDate(String date)
Sets the"Date"header ornullfor 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 ornullfor none.- Since:
- 1.5
-
setETag
public HttpHeaders setETag(String etag)
Sets the"ETag"header ornullfor 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 ornullfor none.- Since:
- 1.5
-
setExpires
public HttpHeaders setExpires(String expires)
Sets the"Expires"header ornullfor 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 ornullfor none.- Since:
- 1.5
-
setIfModifiedSince
public HttpHeaders setIfModifiedSince(String ifModifiedSince)
Sets the"If-Modified-Since"header ornullfor 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 ornullfor none.- Since:
- 1.5
-
setIfMatch
public HttpHeaders setIfMatch(String ifMatch)
Sets the"If-Match"header ornullfor 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 ornullfor none.- Since:
- 1.5
-
setIfNoneMatch
public HttpHeaders setIfNoneMatch(String ifNoneMatch)
Sets the"If-None-Match"header ornullfor 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 ornullfor none.- Since:
- 1.5
-
setIfUnmodifiedSince
public HttpHeaders setIfUnmodifiedSince(String ifUnmodifiedSince)
Sets the"If-Unmodified-Since"header ornullfor 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 ornullfor none.- Since:
- 1.14
-
setIfRange
public HttpHeaders setIfRange(String ifRange)
Sets the"If-Range"header ornullfor 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 ornullfor none.- Since:
- 1.5
-
setLastModified
public HttpHeaders setLastModified(String lastModified)
Sets the"Last-Modified"header ornullfor 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 ornullfor none.- Since:
- 1.5
-
setLocation
public HttpHeaders setLocation(String location)
Sets the"Location"header ornullfor 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 ornullfor none.- Since:
- 1.5
-
setMimeVersion
public HttpHeaders setMimeVersion(String mimeVersion)
Sets the"MIME-Version"header ornullfor 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 ornullfor none.- Since:
- 1.5
-
setRange
public HttpHeaders setRange(String range)
Sets the"Range"header ornullfor 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 ornullfor none.- Since:
- 1.5
-
setRetryAfter
public HttpHeaders setRetryAfter(String retryAfter)
Sets the"Retry-After"header ornullfor 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 ornullfor none.- Since:
- 1.5
-
setUserAgent
public HttpHeaders setUserAgent(String userAgent)
Sets the"User-Agent"header ornullfor 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 ornullfor none.- Since:
- 1.5
-
getAuthenticateAsList
public final List<String> getAuthenticateAsList()
Returns all"WWW-Authenticate"headers ornullfor none.- Since:
- 1.16
-
setAuthenticate
public HttpHeaders setAuthenticate(String authenticate)
Sets the"WWW-Authenticate"header ornullfor 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 ornullfor none.- Since:
- 1.14
-
setAge
public HttpHeaders setAge(Long age)
Sets the"Age"header ornullfor 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 theauthorizationheader 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 anWriterfor Multi-part requests.- Parameters:
headers- HTTP headerslogbuf- log buffer ornullfor nonelogger- logger ornullfor none. Logger must be specified if log buffer is specifiedwriter- Writer where HTTP headers will be serialized to ornullfor none- Throws:
IOException- Since:
- 1.9
-
fromHttpResponse
public final void fromHttpResponse(LowLevelHttpResponse response, StringBuilder logger) throws IOException
Puts all headers of theLowLevelHttpResponseinto thisHttpHeadersobject.- Parameters:
response- Response from which the headers are copiedlogger-StringBuilderto which logging output is added ornullto 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
nullif 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 theHttpHeadersobject into thisHttpHeadersobject.- Parameters:
headers-HttpHeadersfrom where the headers are taken- Since:
- 1.10
-
-