Class HttpHeaders (1.41.8)

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.

Inheritance

Object > AbstractMap > GenericData > HttpHeaders

Static Methods

serializeHeadersForMultipartRequests(HttpHeaders headers, StringBuilder logbuf, Logger logger, Writer writer)

public static void serializeHeadersForMultipartRequests(HttpHeaders headers, StringBuilder logbuf, Logger logger, Writer writer)

Serializes headers to an Writer for Multi-part requests.

Parameters
NameDescription
headersHttpHeaders

HTTP headers

logbufStringBuilder

log buffer or null for none

loggerLogger

logger or null for none. Logger must be specified if log buffer is specified

writerWriter

Writer where HTTP headers will be serialized to or null for none

Exceptions
TypeDescription
IOException

Constructors

HttpHeaders()

public HttpHeaders()

Methods

addWarning(String warning)

public HttpHeaders addWarning(String warning)

Adds the "Warning" header or null for none.

Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

Parameter
NameDescription
warningString
Returns
TypeDescription
HttpHeaders

clone()

public HttpHeaders clone()

Makes a "deep" clone of the generic data, in which the clone is completely independent of the original.

Returns
TypeDescription
HttpHeaders
Overrides

fromHttpHeaders(HttpHeaders headers)

public final void fromHttpHeaders(HttpHeaders headers)

Puts all headers of the HttpHeaders object into this HttpHeaders object.

Parameter
NameDescription
headersHttpHeaders

HttpHeaders from where the headers are taken

fromHttpResponse(LowLevelHttpResponse response, StringBuilder logger)

public final void fromHttpResponse(LowLevelHttpResponse response, StringBuilder logger)

Puts all headers of the LowLevelHttpResponse into this HttpHeaders object.

Parameters
NameDescription
responseLowLevelHttpResponse

Response from which the headers are copied

loggerStringBuilder

StringBuilder to which logging output is added or null to disable logging

Exceptions
TypeDescription
IOException

getAccept()

public final String getAccept()

Returns the first "Accept" header or null for none.

Returns
TypeDescription
String

getAcceptEncoding()

public final String getAcceptEncoding()

Returns the first "Accept-Encoding" header or null for none.

Returns
TypeDescription
String

getAge()

public final Long getAge()

Returns the first "Age" header or null for none.

Returns
TypeDescription
Long

getAuthenticate()

public final String getAuthenticate()

Returns the first "WWW-Authenticate" header or null for none.

Returns
TypeDescription
String

getAuthenticateAsList()

public final List<String> getAuthenticateAsList()

Returns all "WWW-Authenticate" headers or null for none.

Returns
TypeDescription
List<String>

getAuthorization()

public final String getAuthorization()

Returns the first "Authorization" header or null for none.

Returns
TypeDescription
String

getAuthorizationAsList()

public final List<String> getAuthorizationAsList()

Returns all "Authorization" headers or null for none.

Returns
TypeDescription
List<String>

getCacheControl()

public final String getCacheControl()

Returns the first "Cache-Control" header or null for none.

Returns
TypeDescription
String

getContentEncoding()

public final String getContentEncoding()

Returns the first "Content-Encoding" header or null for none.

Returns
TypeDescription
String

getContentLength()

public final Long getContentLength()

Returns the first "Content-Length" header or null for none.

Returns
TypeDescription
Long

getContentMD5()

public final String getContentMD5()

Returns the first "Content-MD5" header or null for none.

Returns
TypeDescription
String

getContentRange()

public final String getContentRange()

Returns the first "Content-Range" header or null for none.

Returns
TypeDescription
String

getContentType()

public final String getContentType()

Returns the first "Content-Type" header or null for none.

Returns
TypeDescription
String

getCookie()

public final String getCookie()

Returns the first "Cookie" header or null for none.

See Cookie Specification.

Returns
TypeDescription
String

getDate()

public final String getDate()

Returns the first "Date" header or null for none.

Returns
TypeDescription
String

getETag()

public final String getETag()

Returns the first "ETag" header or null for none.

Returns
TypeDescription
String

getExpires()

public final String getExpires()

Returns the first "Expires" header or null for none.

Returns
TypeDescription
String

getFirstHeaderStringValue(String name)

public String getFirstHeaderStringValue(String name)

Returns the first header string value for the given header name.

Parameter
NameDescription
nameString

header name (may be any case)

Returns
TypeDescription
String

first header string value or null if not found

getHeaderStringValues(String name)

public List<String> getHeaderStringValues(String name)

Returns an unmodifiable list of the header string values for the given header name.

Parameter
NameDescription
nameString

header name (may be any case)

Returns
TypeDescription
List<String>

header string values or empty if not found

getIfMatch()

public final String getIfMatch()

Returns the first "If-Match" header or null for none.

Returns
TypeDescription
String

getIfModifiedSince()

public final String getIfModifiedSince()

Returns the first "If-Modified-Since" header or null for none.

Returns
TypeDescription
String

getIfNoneMatch()

public final String getIfNoneMatch()

Returns the first "If-None-Match" header or null for none.

Returns
TypeDescription
String

getIfRange()

public final String getIfRange()

Returns the first "If-Range" header or null for none.

Returns
TypeDescription
String

getIfUnmodifiedSince()

public final String getIfUnmodifiedSince()

Returns the first "If-Unmodified-Since" header or null for none.

Returns
TypeDescription
String

getLastModified()

public final String getLastModified()

Returns the first "Last-Modified" header or null for none.

Returns
TypeDescription
String

getLocation()

public final String getLocation()

Returns the first "Location" header or null for none.

Returns
TypeDescription
String

getMimeVersion()

public final String getMimeVersion()

Returns the first "MIME-Version" header or null for none.

Returns
TypeDescription
String

getRange()

public final String getRange()

Returns the first "Range" header or null for none.

Returns
TypeDescription
String

getRetryAfter()

public final String getRetryAfter()

Returns the first "Retry-After" header or null for none.

Returns
TypeDescription
String

getUserAgent()

public final String getUserAgent()

Returns the first "User-Agent" header or null for none.

Returns
TypeDescription
String

getWarning()

public final List<String> getWarning()

Returns all "Warning" headers or null for none.

Returns
TypeDescription
List<String>

set(String fieldName, Object value)

public HttpHeaders set(String fieldName, Object value)

Sets the given field value (may be null) for the given field name. Any existing value for the field will be overwritten. It may be more slightly more efficient than #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.

Parameters
NameDescription
fieldNameString
valueObject
Returns
TypeDescription
HttpHeaders
Overrides

setAccept(String accept)

public HttpHeaders setAccept(String accept)

Sets the "Accept" header or null for none.

Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

Parameter
NameDescription
acceptString
Returns
TypeDescription
HttpHeaders

setAcceptEncoding(String acceptEncoding)

public HttpHeaders setAcceptEncoding(String acceptEncoding)

Sets the "Accept-Encoding" header or null for none.

By default, this is "gzip".

Parameter
NameDescription
acceptEncodingString
Returns
TypeDescription
HttpHeaders

setAge(Long age)

public HttpHeaders setAge(Long age)

Sets the "Age" header or null for none.

Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

Parameter
NameDescription
ageLong
Returns
TypeDescription
HttpHeaders

setAuthenticate(String authenticate)

public HttpHeaders setAuthenticate(String authenticate)

Sets the "WWW-Authenticate" header or null for none.

Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

Parameter
NameDescription
authenticateString
Returns
TypeDescription
HttpHeaders

setAuthorization(String authorization)

public HttpHeaders setAuthorization(String authorization)

Sets the "Authorization" header or null for none.

Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

Parameter
NameDescription
authorizationString
Returns
TypeDescription
HttpHeaders

setAuthorization(List<String> authorization)

public HttpHeaders setAuthorization(List<String> authorization)

Sets the "Authorization" header or null for none.

Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

Parameter
NameDescription
authorizationList<String>
Returns
TypeDescription
HttpHeaders

setBasicAuthentication(String username, String password)

public HttpHeaders setBasicAuthentication(String username, String password)

Sets the #authorization 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.

Parameters
NameDescription
usernameString
passwordString
Returns
TypeDescription
HttpHeaders

setCacheControl(String cacheControl)

public HttpHeaders setCacheControl(String cacheControl)

Sets the "Cache-Control" header or null for none.

Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

Parameter
NameDescription
cacheControlString
Returns
TypeDescription
HttpHeaders

setContentEncoding(String contentEncoding)

public HttpHeaders setContentEncoding(String contentEncoding)

Sets the "Content-Encoding" header or null for none.

Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

Parameter
NameDescription
contentEncodingString
Returns
TypeDescription
HttpHeaders

setContentLength(Long contentLength)

public HttpHeaders setContentLength(Long contentLength)

Sets the "Content-Length" header or null for none.

Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

Parameter
NameDescription
contentLengthLong
Returns
TypeDescription
HttpHeaders

setContentMD5(String contentMD5)

public HttpHeaders setContentMD5(String contentMD5)

Sets the "Content-MD5" header or null for none.

Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

Parameter
NameDescription
contentMD5String
Returns
TypeDescription
HttpHeaders

setContentRange(String contentRange)

public HttpHeaders setContentRange(String contentRange)

Sets the "Content-Range" header or null for none.

Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

Parameter
NameDescription
contentRangeString
Returns
TypeDescription
HttpHeaders

setContentType(String contentType)

public HttpHeaders setContentType(String contentType)

Sets the "Content-Type" header or null for none.

Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

Parameter
NameDescription
contentTypeString
Returns
TypeDescription
HttpHeaders

setCookie(String cookie)

public HttpHeaders setCookie(String cookie)

Sets the "Cookie" header or null for none.

Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

Parameter
NameDescription
cookieString
Returns
TypeDescription
HttpHeaders

setDate(String date)

public HttpHeaders setDate(String date)

Sets the "Date" header or null for none.

Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

Parameter
NameDescription
dateString
Returns
TypeDescription
HttpHeaders

setETag(String etag)

public HttpHeaders setETag(String etag)

Sets the "ETag" header or null for none.

Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

Parameter
NameDescription
etagString
Returns
TypeDescription
HttpHeaders

setExpires(String expires)

public HttpHeaders setExpires(String expires)

Sets the "Expires" header or null for none.

Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

Parameter
NameDescription
expiresString
Returns
TypeDescription
HttpHeaders

setIfMatch(String ifMatch)

public HttpHeaders setIfMatch(String ifMatch)

Sets the "If-Match" header or null for none.

Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

Parameter
NameDescription
ifMatchString
Returns
TypeDescription
HttpHeaders

setIfModifiedSince(String ifModifiedSince)

public HttpHeaders setIfModifiedSince(String ifModifiedSince)

Sets the "If-Modified-Since" header or null for none.

Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

Parameter
NameDescription
ifModifiedSinceString
Returns
TypeDescription
HttpHeaders

setIfNoneMatch(String ifNoneMatch)

public HttpHeaders setIfNoneMatch(String ifNoneMatch)

Sets the "If-None-Match" header or null for none.

Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

Parameter
NameDescription
ifNoneMatchString
Returns
TypeDescription
HttpHeaders

setIfRange(String ifRange)

public HttpHeaders setIfRange(String ifRange)

Sets the "If-Range" header or null for none.

Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

Parameter
NameDescription
ifRangeString
Returns
TypeDescription
HttpHeaders

setIfUnmodifiedSince(String ifUnmodifiedSince)

public HttpHeaders setIfUnmodifiedSince(String ifUnmodifiedSince)

Sets the "If-Unmodified-Since" header or null for none.

Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

Parameter
NameDescription
ifUnmodifiedSinceString
Returns
TypeDescription
HttpHeaders

setLastModified(String lastModified)

public HttpHeaders setLastModified(String lastModified)

Sets the "Last-Modified" header or null for none.

Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

Parameter
NameDescription
lastModifiedString
Returns
TypeDescription
HttpHeaders

setLocation(String location)

public HttpHeaders setLocation(String location)

Sets the "Location" header or null for none.

Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

Parameter
NameDescription
locationString
Returns
TypeDescription
HttpHeaders

setMimeVersion(String mimeVersion)

public HttpHeaders setMimeVersion(String mimeVersion)

Sets the "MIME-Version" header or null for none.

Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

Parameter
NameDescription
mimeVersionString
Returns
TypeDescription
HttpHeaders

setRange(String range)

public HttpHeaders setRange(String range)

Sets the "Range" header or null for none.

Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

Parameter
NameDescription
rangeString
Returns
TypeDescription
HttpHeaders

setRetryAfter(String retryAfter)

public HttpHeaders setRetryAfter(String retryAfter)

Sets the "Retry-After" header or null for none.

Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

Parameter
NameDescription
retryAfterString
Returns
TypeDescription
HttpHeaders

setUserAgent(String userAgent)

public HttpHeaders setUserAgent(String userAgent)

Sets the "User-Agent" header or null for none.

Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

Parameter
NameDescription
userAgentString
Returns
TypeDescription
HttpHeaders