Class HttpHeaderBean

java.lang.Object
org.apache.juneau.http.header.HttpHeaderBean
All Implemented Interfaces:
HttpHeader
Direct Known Subclasses:
HttpBooleanHeader, HttpCsvHeader, HttpDateHeader, HttpEntityTagHeader, HttpEntityTagsHeader, HttpIntegerHeader, HttpLongHeader, HttpMediaRangesHeader, HttpMediaTypeHeader, HttpStringHeader, HttpStringRangesHeader, HttpUriHeader, IfRange, RetryAfter

public class HttpHeaderBean extends Object implements HttpHeader
Root concrete implementation of HttpHeader.

Holds a name/value pair where the value may be supplied eagerly (as a String) or lazily (via a Supplier). A lazy supplier returning null signals that the header should be omitted from the request.

Create instances via the static factory methods:

// Eager HttpHeader h1 = HttpHeaderBean.of("X-My-Header", "my-value"); // Lazy — evaluated at request-send time HttpHeader h2 = HttpHeaderBean.of("Authorization", () -> tokenSupplier.get());

See Also:
Since:
9.2.1
  • Constructor Details

    • HttpHeaderBean

      protected HttpHeaderBean(String name, String value)
      Constructor.
      Parameters:
      name - The header name. Must not be null.
      value - The header value. May be null.
    • HttpHeaderBean

      protected HttpHeaderBean(String name, Supplier<String> valueSupplier)
      Constructor with lazy value supplier.
      Parameters:
      name - The header name. Must not be null.
      valueSupplier - Supplier that provides the header value at request time. Must not be null.
  • Method Details

    • of

      public static HttpHeaderBean of(String name, String value)
      Creates an HttpHeaderBean with an eager string value.
      Parameters:
      name - The header name. Must not be null.
      value - The header value. May be null to indicate the header should be omitted.
      Returns:
      A new instance. Never null.
    • of

      public static HttpHeaderBean of(String name, Supplier<String> valueSupplier)
      Creates an HttpHeaderBean with a lazy value supplier.

      The supplier is evaluated at request-send time; if it returns null the header is omitted.

      Parameters:
      name - The header name. Must not be null.
      valueSupplier - Supplier for the header value. Must not be null.
      Returns:
      A new instance. Never null.
    • getName

      public String getName()
      Description copied from interface: HttpHeader
      Returns the header name.
      Specified by:
      getName in interface HttpHeader
      Returns:
      The header name. Never null.
    • getValue

      public String getValue()
      Description copied from interface: HttpHeader
      Returns the header value, or null if the header has no value.
      Specified by:
      getValue in interface HttpHeader
      Returns:
      The header value, possibly null.
    • equalsIgnoreCase

      public boolean equalsIgnoreCase(String other)
      Returns true if the header value is equal to the given value, ignoring case.
      Parameters:
      other - The value to compare against. May be null.
      Returns:
      true if the value is equal, ignoring case.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object