Class BasicStringHeader

java.lang.Object
org.apache.juneau.http.header.BasicHeader
org.apache.juneau.http.header.BasicStringHeader
All Implemented Interfaces:
Serializable, Cloneable, Header, NameValuePair
Direct Known Subclasses:
AcceptRanges, Authorization, BasicMediaRangesHeader, BasicMediaTypeHeader, CacheControl, ClientVersion, Connection, ContentEncoding, ContentRange, Expect, Forwarded, From, Host, Origin, Pragma, ProxyAuthenticate, ProxyAuthorization, Range, Server, Trailer, TransferEncoding, UserAgent, Vary, Warning, WwwAuthenticate

public class BasicStringHeader extends BasicHeader
Category of headers that consist of a single string value.

Example

Host: www.myhost.com:8080

See Also:
  • Constructor Details

  • Method Details

    • of

      public static BasicStringHeader of(String name, String value)
      Static creator.
      Parameters:
      name - The header name.
      value - The header value.
      Can be null.
      Returns:
      A new header bean, or null if the value is null.
      Throws:
      IllegalArgumentException - If name is null or empty.
    • of

      public static BasicStringHeader of(String name, Supplier<String> value)
      Static creator with delayed value.

      Header value is re-evaluated on each call to getValue().

      Parameters:
      name - The header name.
      value - The supplier of the header value.
      Can be null.
      Returns:
      A new header bean, or null if the value is null.
      Throws:
      IllegalArgumentException - If name is null or empty.
    • ofPair

      public static BasicStringHeader ofPair(String pair)
      Creates a Header from a name/value pair string (e.g. "Foo: bar")
      Parameters:
      pair - The pair string.
      Returns:
      A new header bean.
    • getValue

      public String getValue()
      Specified by:
      getValue in interface NameValuePair
      Overrides:
      getValue in class BasicHeader
    • asString

      Description copied from class: BasicHeader
      Returns the value of this header as a string.
      Overrides:
      asString in class BasicHeader
      Returns:
      The value of this header as a string, or Optional.empty() if the value is null
    • assertString

      Provides the ability to perform fluent-style assertions on this header.
      Examples:

      // Validates the content type header is provided. client .get(URL) .run() .getHeader("Content-Type").assertString().exists();

      Returns:
      A new fluent assertion object.
      Throws:
      AssertionError - If assertion failed.
    • orElse

      public String orElse(String other)
      Return the value if present, otherwise return other.

      This is a shortened form for calling asString().orElse(other).

      Overrides:
      orElse in class BasicHeader
      Parameters:
      other - The value to be returned if there is no value present, can be null.
      Returns:
      The value, if present, otherwise other.