- All Superinterfaces:
Iterable<Http.HeaderValue>
- All Known Subinterfaces:
HeadersClientRequest,HeadersClientResponse,HeadersServerRequest,HeadersServerResponse,HeadersWritable<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
Http.HeaderValue.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 (Http.Header.ACCEPTheader) content types in quality factor order.all(Http.HeaderName name, Supplier<List<String>> defaultSupplier) Get all values of a header.Deprecated, for removal: This API element is subject to removal in a future version.booleancontains(Http.HeaderName name) Whether these headers contain a header with the provided name.booleancontains(Http.HeaderValue value) Whether these headers contain a header with the provided name and value.default OptionalLongContent length if defined.default Optional<HttpMediaType>Content type (if defined).first(Http.HeaderName headerName) Returns a first header value.get(Http.HeaderName name) Get a header value.default booleanisAccepted(MediaType mediaType) Whether this media type is accepted by these headers.intsize()Number of headers in these headers.toMap()Deprecated, for removal: This API element is subject to removal in a future version.use other methods to handle headers, preferably using pull approachvalue(Http.HeaderName headerName) values(Http.HeaderName headerName) Returns an unmodifiableListof 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
Deprecated, for removal: This API element is subject to removal in a future version.Returns an unmodifiableListof all header fields - each element represents a value of a single header field in the request. Consider to usevalue(io.helidon.common.http.Http.HeaderName)orall(io.helidon.common.http.Http.HeaderName, java.util.function.Supplier)method instead.Always returns a List, which may be empty if the parameter is not present.
- Parameters:
headerName- the header name- Returns:
- a
Listof values with zero or greater size - Throws:
NullPointerException- ifheaderNameisnull- See Also:
-
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:
trueif the header is defined
-
contains
Whether these headers contain a header with the provided name and value.- Parameters:
value- value of the header- Returns:
trueif 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 singleStringpotentially concatenated using comma character fromallheader fields.Accordingly 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- ifheaderNameisnull- See Also:
-
first
Returns a first header value.- Parameters:
headerName- the header name- Returns:
- the first value
- Throws:
NullPointerException- ifheaderNameisnull
-
values
Returns an unmodifiableListof 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
headerNamewhere 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 parameter is not present.
- Parameters:
headerName- the header name- Returns:
- a
Listof values with zero or greater size, nevernull - Throws:
NullPointerException- ifheaderNameisnull- 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 (Http.Header.ACCEPTheader) content types in quality factor order. Nevernull. Returns an empty list by default.- Returns:
- A list of acceptedTypes media types.
-
isAccepted
Whether this media type is accepted by these headers. As this method is useful only for server request headers, it returnstrueby default.- Parameters:
mediaType- media type to test- Returns:
trueif this media type would be accepted
-
toMap
Deprecated, for removal: This API element is subject to removal in a future version.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
-
all(io.helidon.common.http.Http.HeaderName, java.util.function.Supplier)instead