- All Known Subinterfaces:
ClientRequestHeaders
,ClientResponseHeaders
,ClientResponseTrailers
,ServerRequestHeaders
,ServerResponseHeaders
,ServerResponseTrailers
,WritableHeaders<B>
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 Summary
Modifier and TypeMethodDescriptionReturns a list of acceptedTypes (HeaderNames.ACCEPT
header) content discoveryTypes in quality factor order.all
(HeaderName name, Supplier<List<String>> defaultSupplier) Get all values of a header.boolean
Whether these headers contain a header with the provided name and value.boolean
contains
(HeaderName name) Whether these headers contain a header with the provided name.default OptionalLong
Content length if defined.default Optional
<HttpMediaType> Content type (if defined).first
(HeaderName headerName) Returns a first header value.get
(HeaderName name) Get a header value.default boolean
isAccepted
(MediaType mediaType) Whether this media type is accepted by these headers.int
size()
Number of headers in these headers.stream()
A sequential stream with these headers as the source.toMap()
Deprecated.use other methods to handle headers, preferably using pull approachvalue
(HeaderName headerName) Returns a header value as a singleString
potentially concatenated using comma character fromall(HeaderName, java.util.function.Supplier)
header fields.values
(HeaderName headerName) Returns an unmodifiableList
of all comma separated header value parts - Such segmentation is NOT valid for all header semantics, however it is very common.Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
-
Method Details
-
all
Get all values of a header.- Parameters:
name
- name of the headerdefaultSupplier
- supplier to obtain default values if the header is not present- Returns:
- list of header values
-
contains
Whether these headers contain a header with the provided name.- Parameters:
name
- header name- Returns:
true
if the header is defined
-
contains
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
Get a header value.- Parameters:
name
- name of the header- Returns:
- value if present
- Throws:
NoSuchElementException
- in case the header is not present
-
value
Returns a header value as a singleString
potentially concatenated using comma character fromall(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
- ifheaderName
isnull
- See Also:
-
first
Returns a first header value.- Parameters:
headerName
- the header name- Returns:
- the first value
- Throws:
NullPointerException
- ifheaderName
isnull
-
values
Returns an unmodifiableList
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, nevernull
- Throws:
NullPointerException
- ifheaderName
isnull
- See Also:
-
contentLength
Content length if defined.- Returns:
- content length or empty if not defined
- See Also:
-
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. Nevernull
. Returns an empty list by default.- Returns:
- A list of acceptedTypes media discoveryTypes.
-
isAccepted
Whether this media type is accepted by these headers. As this method is useful only for server request headers, it returnstrue
by default.- Parameters:
mediaType
- media type to test- Returns:
true
if this media type would be accepted
-
toMap
Deprecated.use other methods to handle headers, preferably using pull approachCreates a multivalued map from these headers. This is extremely inefficient and should not be used.- Returns:
- map of headers
-
stream
A sequential stream with these headers as the source.- Returns:
- stream of header values
-