Class ResponseHeader

java.lang.Object
org.apache.juneau.rest.client.ResponseHeader

public final class ResponseHeader extends Object
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 Details

    • getName

      public String getName()
      Returns the header name.
      Returns:
      The header name. Never null.
    • isPresent

      public boolean isPresent()
      Returns true if this header is present in the response.
      Returns:
      true if present.
    • getValue

      public String getValue()
      Returns the first value of this header, or null if absent.
      Returns:
      The header value, possibly null.
    • orElse

      public String orElse(String defaultValue)
      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 defaultValue if absent.
    • asOptional

      Returns the first value of this header as an Optional.
      Returns:
      An optional containing the first header value, or empty if absent.
    • asInteger

      public int asInteger()
      Returns the first value of this header parsed as an int, or -1 if absent or not parseable.
      Returns:
      The integer value, or -1 if absent or not an integer.
    • asLong

      public long asLong()
      Returns the first value of this header parsed as a long, or -1L if absent or not parseable.
      Returns:
      The long value, or -1L if absent or not a long.
    • getValues

      public List<String> 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

      public List<String> asCsvList()
      Returns the first value as a comma-split list of individual tokens.

      Useful for headers like Accept or Allow that 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 a Boolean.
      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

      public Optional<URI> asUri()
      Returns the first value of this header parsed as a URI.
      Returns:
      The parsed URI, or empty if absent or not a valid URI.
    • asEntityTag

      Returns the first value of this header parsed as a single EntityTag validator (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 of EntityTag validators (e.g. If-Match).
      Returns:
      The parsed entity tags, or EntityTags.EMPTY if absent or not parseable. Never null.
    • 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

      public String toString()
      Overrides:
      toString in class Object