Interface Headers

All Superinterfaces:
Iterable<Header>
All Known Subinterfaces:
ClientRequestHeaders, ClientResponseHeaders, ClientResponseTrailers, ServerRequestHeaders, ServerResponseHeaders, ServerResponseTrailers, WritableHeaders<B>

public interface Headers extends Iterable<Header>
View of HTTP Headers. This API is designed to support both HTTP/1 and HTTP/2. Note that HTTP/2 has all headers lower case (mandatory), while HTTP/1 headers are compared ignoring case. When you configure headers to be sent using HTTP/2, all names will be lowercase. When you configure headers to be sent using HTTP/1, names will be sent as configured. When you receive headers, the stored values (as can be obtained by Header.name()) will be as sent on the transport. These value will be available using any cased names (though performance may be worse if uppercase letters are used to obtain HTTP/2 headers).
  • Method Details

    • all

      List<String> all(HeaderName name, Supplier<List<String>> defaultSupplier)
      Get all values of a header.
      Parameters:
      name - name of the header
      defaultSupplier - supplier to obtain default values if the header is not present
      Returns:
      list of header values
    • contains

      boolean contains(HeaderName name)
      Whether these headers contain a header with the provided name.
      Parameters:
      name - header name
      Returns:
      true if the header is defined
    • contains

      boolean contains(Header value)
      Whether these headers contain a header with the provided name and value.
      Parameters:
      value - value of the header
      Returns:
      true if the header is defined
    • get

      Header get(HeaderName name)
      Get a header value.
      Parameters:
      name - name of the header
      Returns:
      value if present
      Throws:
      NoSuchElementException - in case the header is not present
    • value

      default Optional<String> value(HeaderName headerName)
      Returns a header value as a single String potentially concatenated using comma character from all(HeaderName, java.util.function.Supplier) header fields.

      According to RFC2616, Message Headers:

      Multiple message-header fields with the same field-name MAY be present in a message if and only if the entire field-value for that header field is defined as a comma-separated list [i.e., #(values)]. It MUST be possible to combine the multiple header fields into one "field-name: field-value" pair, without changing the semantics of the message, by appending each subsequent field-value to the first, each separated by a comma.
      Parameters:
      headerName - the header name
      Returns:
      all header values concatenated using comma separator
      Throws:
      NullPointerException - if headerName is null
      See Also:
    • first

      default Optional<String> first(HeaderName headerName)
      Returns a first header value.
      Parameters:
      headerName - the header name
      Returns:
      the first value
      Throws:
      NullPointerException - if headerName is null
    • values

      default List<String> values(HeaderName headerName)
      Returns an unmodifiable List of all comma separated header value parts - Such segmentation is NOT valid for all header semantics, however it is very common. Refer to actual header semantics standard/description before use.

      Result is composed from all header fields with requested headerName where each header value is tokenized by a comma character. Tokenization respects value quoting by double-quote character.

      Always returns a List, which may be empty if the header is not present.

      Parameters:
      headerName - the header name
      Returns:
      a List of values with zero or greater size, never null
      Throws:
      NullPointerException - if headerName is null
      See Also:
    • contentLength

      default OptionalLong contentLength()
      Content length if defined.
      Returns:
      content length or empty if not defined
      See Also:
    • contentType

      default Optional<HttpMediaType> contentType()
      Content type (if defined).
      Returns:
      content type, empty if content type is not present
      See Also:
    • size

      int size()
      Number of headers in these headers.
      Returns:
      size of these headers
    • acceptedTypes

      List<HttpMediaType> acceptedTypes()
      Returns a list of acceptedTypes (HeaderNames.ACCEPT header) content discoveryTypes in quality factor order. Never null. Returns an empty list by default.
      Returns:
      A list of acceptedTypes media discoveryTypes.
    • isAccepted

      default boolean isAccepted(MediaType mediaType)
      Whether this media type is accepted by these headers. As this method is useful only for server request headers, it returns true by default.
      Parameters:
      mediaType - media type to test
      Returns:
      true if this media type would be accepted
    • toMap

      @Deprecated default Map<String,List<String>> toMap()
      Deprecated.
      use other methods to handle headers, preferably using pull approach
      Creates a multivalued map from these headers. This is extremely inefficient and should not be used.
      Returns:
      map of headers
    • stream

      default Stream<Header> stream()
      A sequential stream with these headers as the source.
      Returns:
      stream of header values