Class HttpHeaders
null
is not allowed as a name or value of a header. Names are case-insensitive.
Implementation is not thread-safe.
- Since:
- 1.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
LowLevelHttpRequest which will call the .parseHeader() method for every header added.private static final class
State container forparseHeader(String, String, ParseHeaderState)
.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,
V>, AbstractMap.SimpleImmutableEntry<K, V> -
Field Summary
FieldsModifier and TypeFieldDescription"Accept"
header."Accept-Encoding"
header."Age"
header."WWW-Authenticate"
header."Authorization"
header."Cache-Control"
header."Content-Encoding"
header."Content-Length"
header."Content-MD5"
header."Content-Range"
header."Content-Type"
header."Cookie"
header."Date"
header."ETag"
header."Expires"
header."If-Match"
header."If-Modified-Since"
header."If-None-Match"
header."If-Range"
header."If-Unmodified-Since"
header."Last-Modified"
header."Location"
header."MIME-Version"
header."Range"
header."Retry-After"
header."User-Agent"
header."Warning"
header. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static void
addHeader
(Logger logger, StringBuilder logbuf, StringBuilder curlbuf, LowLevelHttpRequest lowLevelHttpRequest, String name, Object value, Writer writer) addWarning
(String warning) Adds the"Warning"
header ornull
for none.clone()
Makes a "deep" clone of the generic data, in which the clone is completely independent of the original.final void
fromHttpHeaders
(HttpHeaders headers) Puts all headers of theHttpHeaders
object into thisHttpHeaders
object.final void
fromHttpResponse
(LowLevelHttpResponse response, StringBuilder logger) Puts all headers of theLowLevelHttpResponse
into thisHttpHeaders
object.final String
Returns the first"Accept"
header ornull
for none.final String
Returns the first"Accept-Encoding"
header ornull
for none.final Long
getAge()
Returns the first"Age"
header ornull
for none.private <T> List
<T> getAsList
(T passedValue) Returns the list value to use for the given parameter passed to the setter method.final String
Returns the first"WWW-Authenticate"
header ornull
for none.Returns all"WWW-Authenticate"
headers ornull
for none.final String
Returns the first"Authorization"
header ornull
for none.Returns all"Authorization"
headers ornull
for none.final String
Returns the first"Cache-Control"
header ornull
for none.final String
Returns the first"Content-Encoding"
header ornull
for none.final Long
Returns the first"Content-Length"
header ornull
for none.final String
Returns the first"Content-MD5"
header ornull
for none.final String
Returns the first"Content-Range"
header ornull
for none.final String
Returns the first"Content-Type"
header ornull
for none.final String
Returns the first"Cookie"
header ornull
for none.final String
getDate()
Returns the first"Date"
header ornull
for none.final String
getETag()
Returns the first"ETag"
header ornull
for none.final String
Returns the first"Expires"
header ornull
for none.Returns the first header string value for the given header name.private <T> T
getFirstHeaderValue
(List<T> internalValue) Returns the first header value based on the given internal list value.getHeaderStringValues
(String name) Returns an unmodifiable list of the header string values for the given header name.final String
Returns the first"If-Match"
header ornull
for none.final String
Returns the first"If-Modified-Since"
header ornull
for none.final String
Returns the first"If-None-Match"
header ornull
for none.final String
Returns the first"If-Range"
header ornull
for none.final String
Returns the first"If-Unmodified-Since"
header ornull
for none.final String
Returns the first"Last-Modified"
header ornull
for none.final String
Returns the first"Location"
header ornull
for none.final String
Returns the first"MIME-Version"
header ornull
for none.final String
getRange()
Returns the first"Range"
header ornull
for none.final String
Returns the first"Retry-After"
header ornull
for none.final String
Returns the first"User-Agent"
header ornull
for none.Returns all"Warning"
headers ornull
for none.(package private) void
parseHeader
(String headerName, String headerValue, HttpHeaders.ParseHeaderState state) Parses the specified case-insensitive header pair into this HttpHeaders instance.private static Object
parseValue
(Type valueType, List<Type> context, String value) (package private) static void
serializeHeaders
(HttpHeaders headers, StringBuilder logbuf, StringBuilder curlbuf, Logger logger, LowLevelHttpRequest lowLevelHttpRequest) Serializes headers to anLowLevelHttpRequest
.(package private) static void
serializeHeaders
(HttpHeaders headers, StringBuilder logbuf, StringBuilder curlbuf, Logger logger, LowLevelHttpRequest lowLevelHttpRequest, Writer writer) static void
serializeHeadersForMultipartRequests
(HttpHeaders headers, StringBuilder logbuf, Logger logger, Writer writer) Serializes headers to anWriter
for Multi-part requests.Sets the given field value (may benull
) for the given field name.Sets the"Accept"
header ornull
for none.setAcceptEncoding
(String acceptEncoding) Sets the"Accept-Encoding"
header ornull
for none.Sets the"Age"
header ornull
for none.setAuthenticate
(String authenticate) Sets the"WWW-Authenticate"
header ornull
for none.setAuthorization
(String authorization) Sets the"Authorization"
header ornull
for none.setAuthorization
(List<String> authorization) Sets the"Authorization"
header ornull
for none.setBasicAuthentication
(String username, String password) Sets theauthorization
header as specified in Basic Authentication Scheme.setCacheControl
(String cacheControl) Sets the"Cache-Control"
header ornull
for none.setContentEncoding
(String contentEncoding) Sets the"Content-Encoding"
header ornull
for none.setContentLength
(Long contentLength) Sets the"Content-Length"
header ornull
for none.setContentMD5
(String contentMD5) Sets the"Content-MD5"
header ornull
for none.setContentRange
(String contentRange) Sets the"Content-Range"
header ornull
for none.setContentType
(String contentType) Sets the"Content-Type"
header ornull
for none.Sets the"Cookie"
header ornull
for none.Sets the"Date"
header ornull
for none.Sets the"ETag"
header ornull
for none.setExpires
(String expires) Sets the"Expires"
header ornull
for none.setIfMatch
(String ifMatch) Sets the"If-Match"
header ornull
for none.setIfModifiedSince
(String ifModifiedSince) Sets the"If-Modified-Since"
header ornull
for none.setIfNoneMatch
(String ifNoneMatch) Sets the"If-None-Match"
header ornull
for none.setIfRange
(String ifRange) Sets the"If-Range"
header ornull
for none.setIfUnmodifiedSince
(String ifUnmodifiedSince) Sets the"If-Unmodified-Since"
header ornull
for none.setLastModified
(String lastModified) Sets the"Last-Modified"
header ornull
for none.setLocation
(String location) Sets the"Location"
header ornull
for none.setMimeVersion
(String mimeVersion) Sets the"MIME-Version"
header ornull
for none.Sets the"Range"
header ornull
for none.setRetryAfter
(String retryAfter) Sets the"Retry-After"
header ornull
for none.setUserAgent
(String userAgent) Sets the"User-Agent"
header ornull
for none.private static String
toStringValue
(Object headerValue) Returns the string header value for the given header value as an object.Methods inherited from class com.google.api.client.util.GenericData
entrySet, equals, get, getClassInfo, getUnknownKeys, hashCode, put, putAll, remove, setUnknownKeys, toString
Methods inherited from class java.util.AbstractMap
clear, containsKey, containsValue, isEmpty, keySet, size, values
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Field Details
-
accept
"Accept"
header. -
acceptEncoding
"Accept-Encoding"
header. -
authorization
"Authorization"
header. -
cacheControl
"Cache-Control"
header. -
contentEncoding
"Content-Encoding"
header. -
contentLength
"Content-Length"
header. -
contentMD5
"Content-MD5"
header. -
contentRange
"Content-Range"
header. -
contentType
"Content-Type"
header. -
cookie
"Cookie"
header. -
date
"Date"
header. -
etag
"ETag"
header. -
expires
"Expires"
header. -
ifModifiedSince
"If-Modified-Since"
header. -
ifMatch
"If-Match"
header. -
ifNoneMatch
"If-None-Match"
header. -
ifUnmodifiedSince
"If-Unmodified-Since"
header. -
ifRange
"If-Range"
header. -
lastModified
"Last-Modified"
header. -
location
"Location"
header. -
mimeVersion
"MIME-Version"
header. -
range
"Range"
header. -
retryAfter
"Retry-After"
header. -
userAgent
"User-Agent"
header. -
warning
"Warning"
header. -
authenticate
"WWW-Authenticate"
header. -
age
"Age"
header.
-
-
Constructor Details
-
HttpHeaders
public HttpHeaders()
-
-
Method Details
-
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
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
Returns the first"Accept"
header ornull
for none.- Since:
- 1.5
-
setAccept
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
Returns the first"Accept-Encoding"
header ornull
for none.- Since:
- 1.5
-
setAcceptEncoding
Sets the"Accept-Encoding"
header ornull
for none.By default, this is
"gzip"
.- Since:
- 1.5
-
getAuthorization
Returns the first"Authorization"
header ornull
for none.- Since:
- 1.5
-
getAuthorizationAsList
Returns all"Authorization"
headers ornull
for none.- Since:
- 1.13
-
setAuthorization
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
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
Returns the first"Cache-Control"
header ornull
for none.- Since:
- 1.5
-
setCacheControl
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
Returns the first"Content-Encoding"
header ornull
for none.- Since:
- 1.5
-
setContentEncoding
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
Returns the first"Content-Length"
header ornull
for none.- Since:
- 1.5
-
setContentLength
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
Returns the first"Content-MD5"
header ornull
for none.- Since:
- 1.5
-
setContentMD5
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
Returns the first"Content-Range"
header ornull
for none.- Since:
- 1.5
-
setContentRange
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
Returns the first"Content-Type"
header ornull
for none.- Since:
- 1.5
-
setContentType
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
- Since:
- 1.6
-
setCookie
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
Returns the first"Date"
header ornull
for none.- Since:
- 1.5
-
setDate
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
Returns the first"ETag"
header ornull
for none.- Since:
- 1.5
-
setETag
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
Returns the first"Expires"
header ornull
for none.- Since:
- 1.5
-
setExpires
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
Returns the first"If-Modified-Since"
header ornull
for none.- Since:
- 1.5
-
setIfModifiedSince
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
Returns the first"If-Match"
header ornull
for none.- Since:
- 1.5
-
setIfMatch
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
Returns the first"If-None-Match"
header ornull
for none.- Since:
- 1.5
-
setIfNoneMatch
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
Returns the first"If-Unmodified-Since"
header ornull
for none.- Since:
- 1.5
-
setIfUnmodifiedSince
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
Returns the first"If-Range"
header ornull
for none.- Since:
- 1.14
-
setIfRange
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
Returns the first"Last-Modified"
header ornull
for none.- Since:
- 1.5
-
setLastModified
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
Returns the first"Location"
header ornull
for none.- Since:
- 1.5
-
setLocation
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
Returns the first"MIME-Version"
header ornull
for none.- Since:
- 1.5
-
setMimeVersion
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
Returns the first"Range"
header ornull
for none.- Since:
- 1.5
-
setRange
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
Returns the first"Retry-After"
header ornull
for none.- Since:
- 1.5
-
setRetryAfter
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
Returns the first"User-Agent"
header ornull
for none.- Since:
- 1.5
-
setUserAgent
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
Returns the first"WWW-Authenticate"
header ornull
for none.- Since:
- 1.5
-
getAuthenticateAsList
Returns all"WWW-Authenticate"
headers ornull
for none.- Since:
- 1.16
-
setAuthenticate
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
-
addWarning
Adds the"Warning"
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.28
-
getWarning
Returns all"Warning"
headers ornull
for none.- Since:
- 1.28
-
getAge
Returns the first"Age"
header ornull
for none.- Since:
- 1.14
-
setAge
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
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
-
addHeader
private static void addHeader(Logger logger, StringBuilder logbuf, StringBuilder curlbuf, LowLevelHttpRequest lowLevelHttpRequest, String name, Object value, Writer writer) throws IOException - Throws:
IOException
-
toStringValue
Returns the string header value for the given header value as an object. -
serializeHeaders
static void serializeHeaders(HttpHeaders headers, StringBuilder logbuf, StringBuilder curlbuf, Logger logger, LowLevelHttpRequest lowLevelHttpRequest) throws IOException Serializes headers to anLowLevelHttpRequest
.- Parameters:
headers
- HTTP headerslogbuf
- log buffer ornull
for nonecurlbuf
- log buffer for logging curl requests ornull
for nonelogger
- logger ornull
for none. Logger must be specified if log buffer is specifiedlowLevelHttpRequest
- low level HTTP request where HTTP headers will be serialized to ornull
for none- Throws:
IOException
-
serializeHeaders
static void serializeHeaders(HttpHeaders headers, StringBuilder logbuf, StringBuilder curlbuf, Logger logger, LowLevelHttpRequest lowLevelHttpRequest, Writer writer) throws IOException - Throws:
IOException
-
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
-
getFirstHeaderValue
Returns the first header value based on the given internal list value. -
getAsList
Returns the list value to use for the given parameter passed to the setter method. -
getFirstHeaderStringValue
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
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
Puts all headers of theHttpHeaders
object into thisHttpHeaders
object.- Parameters:
headers
-HttpHeaders
from where the headers are taken- Since:
- 1.10
-
parseHeader
Parses the specified case-insensitive header pair into this HttpHeaders instance. -
parseValue
-