Class Header

java.lang.Object
org.attribyte.api.http.Header

public final class Header extends Object
An immutable HTTP request or response header.
Author:
Matt Hamer
  • Field Details

    • CONTENT_TYPE

      public static final String CONTENT_TYPE
      The content type header.
      See Also:
    • nameComparator

      public static final Comparator<Header> nameComparator
      Compare headers by name. Safe for use by many threads.
    • name

      public final String name
      The header name.
    • values

      public final com.google.common.collect.ImmutableList<String> values
      An immutable list of header values.
  • Constructor Details

    • Header

      public Header(String name, String value)
      Creates a single-valued header.
      Parameters:
      name - The header name.
      value - The header value.
    • Header

      public Header(String name, String[] values)
      Creates a multi-valued header from an array of values.
      Parameters:
      name - The header name.
      values - The header values.
    • Header

      public Header(String name, Collection<String> values)
      Creates a multi-valued header from a collection of values.
      Parameters:
      name - The header name.
      values - The header values.
  • Method Details

    • addValue

      public Header addValue(String value)
      Returns a copy of this header with the new value added.
      Parameters:
      value - The added value.
      Returns:
      The new header.
    • getName

      public String getName()
      Gets the name.
      Returns:
      The name.
    • getValue

      public String getValue()
      Gets the first value.
      Returns:
      The value or an empty string if no value.
    • getValues

      public String[] getValues()
      Gets all the values.
      Returns:
      The values or a zero-length array if none.
    • getValueList

      public com.google.common.collect.ImmutableList<String> getValueList()
      Gets an immutable list of values.
      Returns:
      The values.
    • parseParameters

      public static List<Parameter> parseParameters(String headerValue)
      Parses ';' separated parameters in a header value.
      Parameters:
      headerValue - The header value.
      Returns:
      A list of parameters.
    • getCharset

      public static String getCharset(String contentType, String defaultCharset)
      Gets the charset from a content type header.
      Parameters:
      contentType - The content type header value.
      defaultCharset - The default charset to return if none is specified.
      Returns:
      The charset.
    • toString

      public String toString()
      Overrides:
      toString in class Object