Package org.apache.juneau.rest.client
Class ResponseHeader
java.lang.Object
org.apache.juneau.rest.client.ResponseHeader
A fluent accessor for a named HTTP response header.
Provides convenient typed-access methods for reading header values.
Returns null or empty results when the named header is absent from the response.
Obtain instances via RestResponse.header(String).
See Also:
- Since:
- 9.2.1
-
Method Summary
Modifier and TypeMethodDescriptionReturns the first value of this header parsed as aBoolean.Returns the first value as a comma-split list of individual tokens.Returns the first value of this header parsed as a singleEntityTagvalidator (e.g.Returns the first value of this header parsed as a comma-delimited list ofEntityTagvalidators (e.g.intReturns the first value of this header parsed as anint, or-1if absent or not parseable.longasLong()Returns the first value of this header parsed as along, or-1Lif absent or not parseable.Returns the first value of this header as anOptional.Returns the first value of this header parsed as a q-valued list of string ranges (e.g.asUri()Returns the first value of this header parsed as aURI.Returns the first value of this header parsed as an RFC-1123 HTTP date.getName()Returns the header name.getValue()Returns the first value of this header, ornull if absent.Returns all values of this header.booleanReturnstrue if this header is present in the response.Returns the first value of this header, or the given default if absent.toString()
-
Method Details
-
getName
Returns the header name.- Returns:
- The header name. Never
null .
-
isPresent
Returnstrue if this header is present in the response.- Returns:
true if present.
-
getValue
Returns the first value of this header, ornull if absent.- Returns:
- The header value, possibly
null .
-
orElse
Returns the first value of this header, or the given default if absent.- Parameters:
defaultValue- The default value to return when the header is absent.- Returns:
- The header value, or
defaultValueif absent.
-
asOptional
Returns the first value of this header as anOptional.- Returns:
- An optional containing the first header value, or empty if absent.
-
asInteger
Returns the first value of this header parsed as anint, or-1if absent or not parseable.- Returns:
- The integer value, or
-1if absent or not an integer.
-
asLong
Returns the first value of this header parsed as along, or-1Lif absent or not parseable.- Returns:
- The long value, or
-1Lif absent or not a long.
-
getValues
Returns all values of this header.For repeated headers, this returns each header value in encounter order.
- Returns:
- An unmodifiable list of header values. Never
null , but possibly empty.
-
asCsvList
Returns the first value as a comma-split list of individual tokens.Useful for headers like
AcceptorAllowthat combine multiple values with commas.- Returns:
- A list of trimmed tokens. Never
null , but possibly empty.
-
asBoolean
Returns the first value of this header parsed as aBoolean.- Returns:
- The boolean value, or empty if absent.
-
asZonedDateTime
Returns the first value of this header parsed as an RFC-1123 HTTP date.- Returns:
- The parsed date, or empty if absent or not parseable.
-
asUri
Returns the first value of this header parsed as aURI.- Returns:
- The parsed URI, or empty if absent or not a valid URI.
-
asEntityTag
Returns the first value of this header parsed as a singleEntityTagvalidator (e.g.ETag).- Returns:
- The parsed entity tag, or empty if absent.
-
asEntityTags
Returns the first value of this header parsed as a comma-delimited list ofEntityTagvalidators (e.g.If-Match).- Returns:
- The parsed entity tags, or
EntityTags.EMPTYif absent or not parseable. Nevernull .
-
asStringRanges
Returns the first value of this header parsed as a q-valued list of string ranges (e.g.Accept-Encoding).- Returns:
- The parsed string ranges. Never
null , but possibly empty.
-
toString
-