Interface HttpFields
- All Superinterfaces:
Iterable<HttpField>
,Supplier<HttpFields>
- All Known Subinterfaces:
HttpFields.Mutable
- All Known Implementing Classes:
HttpFields.ImmutableHttpFields
,HttpFields.Mutable.Wrapper
,HttpFields.MutableHttpFields
,HttpTester.Message
,HttpTester.Request
,HttpTester.Response
,ResponseHttpFields
,WebSocketHttpFieldsWrapper
An ordered collection of HttpField
s that represent the HTTP headers
or HTTP trailers of an HTTP request or an HTTP response.
HttpFields
is immutable and typically used in server-side HTTP requests
and client-side HTTP responses, while HttpFields.Mutable
is mutable and
typically used in server-side HTTP responses and client-side HTTP requests.
Access is always more efficient using HttpHeader
keys rather than String
field names.
The primary implementations of HttpFields
have been optimized assuming few
lookup operations, thus typically if many HttpField
s need to looked up, it may be
better to use an Iterator
to find multiple fields in a single iteration.
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic class
Deprecated, for removal: This API element is subject to removal in a future version.static interface
A mutable version ofHttpFields
.static class
Deprecated, for removal: This API element is subject to removal in a future version. -
Field Summary
Modifier and TypeFieldDescriptionstatic final HttpField
A constantHttpField
for the HTTP header:static final HttpField
A constantHttpField
for the HTTP header:static final HttpField
A constantHttpField
for the HTTP header:static final HttpFields
A constant for an immutable and emptyHttpFields
.static final HttpField
A constantHttpField
for the HTTP header: -
Method Summary
Modifier and TypeMethodDescriptiondefault HttpFields
Returns an immutable copy of thisHttpFields
instance.default String
asString()
Returns the HTTP/1.1 string representation of theHttpField
s of this instance.static HttpFields.Mutable
build()
Returns an emptyHttpFields.Mutable
instance.static HttpFields.Mutable
build
(int capacity) Returns an emptyHttpFields.Mutable
instance with the given initialcapacity
.static HttpFields.Mutable
build
(HttpFields fields) Returns a newHttpFields.Mutable
instance containing a copy of all theHttpField
s of the givenHttpFields
parameter.static HttpFields.Mutable
build
(HttpFields fields, EnumSet<HttpHeader> removeFields) Returns a newHttpFields.Mutable
instance containing a copy of all theHttpField
s of the givenHttpFields
, removing theHttpField
s with the given names.static HttpFields.Mutable
build
(HttpFields fields, HttpField replaceField) Returns a newHttpFields.Mutable
instance containing a copy of all theHttpField
s of the givenHttpFields
, replacing with the givenHttpField
all the fieldsHttpField
s with the same name.default boolean
Returns whether this instance contains the given field name.default boolean
Returns whether this instance contains the given field name with the given value.default boolean
contains
(EnumSet<HttpHeader> headers) Returns whether this instance contains at least one of the given field names.default boolean
Returns whether this instance contains the givenHttpField
.default boolean
contains
(HttpHeader header) Returns whether this instance contains the given field name.default boolean
contains
(HttpHeader header, String value) Returns whether this instance contains the givenHttpHeader
with the given value.default boolean
containsLast
(HttpHeader header, String value) Look for a value as the last value in a possible multivalued field.static HttpFields
Returns an immutableHttpFields
instance containing the givenHttpField
s.default HttpFields
get()
Supplies this instance, typically used to supply HTTP trailers.default String
Returns the encoded value of the first field with the given field name, ornull
if no such field is present.default String
get
(HttpHeader header) Returns the encoded value of the first field with the given field name, ornull
if no such header is present.Returns all the values of all the fields with the given field name.getCSV
(HttpHeader header, boolean keepQuotes) Returns all the values of all the fields with the given field name.default long
getDateField
(String name) Returns the value of a date field as the number of milliseconds since the Unix Epoch, or -1 if no such field is present.default long
getDateField
(HttpHeader header) Returns the value of a date field as the number of milliseconds since the Unix Epoch, or -1 if no such field is present.default HttpField
getField
(int index) default HttpField
Returns the firstHttpField
with the given field name, ornull
if no such field is present.default HttpField
getField
(HttpHeader header) Returns the firstHttpField
with the given field name, ornull
if no such field is present.default Enumeration<String>
Deprecated.Returns aSet
of the field names.Returns all theHttpField
s with the given field name.getFields
(HttpHeader header) Returns all theHttpField
s with the given field name.default String
getLast
(HttpHeader header) Returns the encoded value of the last field with the given field name, ornull
if no such header is present.default long
getLongField
(String name) Returns the value of a field as along
value, or -1 if no such field is present.default long
getLongField
(HttpHeader header) Returns the value of a field as along
value, or -1 if no such field is present.getQualityCSV
(String name) Returns all the values of all the fields with the given name, split and sorted in quality order usingQuotedQualityCSV
.getQualityCSV
(HttpHeader header) Returns all the values of all the fields with the given name, split and sorted in quality order usingQuotedQualityCSV
.getQualityCSV
(HttpHeader header, ToIntFunction<String> secondaryOrdering) Returns all the values of all the fields with the given name, split and sorted first in quality order and then optionally further sorted with the given function, usingQuotedQualityCSV
.default Enumeration<String>
Returns anEnumeration
of the encoded values of all the fields with the given name.getValuesList
(String name) Returns a list of the encoded values of all the fields with the given name.getValuesList
(HttpHeader header) Returns a list of the encoded values of all the fields with the given name.default boolean
isEqualTo
(HttpFields that) Returns whether this instance is equal to the given instance.iterator()
default ListIterator<HttpField>
listIterator
(int index) default int
size()
stream()
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
EXPIRES_01JAN1970
A constant
HttpField
for the HTTP header:Expires: Thu, 01 Jan 1970 00:00:00 GMT
-
CONNECTION_CLOSE
A constant
HttpField
for the HTTP header:Connection: close
-
CONNECTION_KEEPALIVE
A constant
HttpField
for the HTTP header:Connection: keep-alive
-
CONTENT_LENGTH_0
A constant
HttpField
for the HTTP header:Content-Length: 0
-
EMPTY
A constant for an immutable and empty
HttpFields
.
-
-
Method Details
-
build
Returns an empty
HttpFields.Mutable
instance.- Returns:
- an empty
HttpFields.Mutable
instance
-
build
Returns an empty
HttpFields.Mutable
instance with the given initialcapacity
.The given
capacity
indicates the initial capacity of the storage for theHttpField
s.When the capacity is exceeded, the storage is resized to accommodate the additional
HttpField
s.- Parameters:
capacity
- the initial capacity of the storage for theHttpField
s- Returns:
- an empty instance with the given initial
capacity
-
build
Returns a new
HttpFields.Mutable
instance containing a copy of all theHttpField
s of the givenHttpFields
parameter.- Parameters:
fields
- theHttpFields
to copy- Returns:
- a new
HttpFields.Mutable
instance containing a copy of the givenHttpFields
-
build
Returns a new
HttpFields.Mutable
instance containing a copy of all theHttpField
s of the givenHttpFields
, replacing with the givenHttpField
all the fieldsHttpField
s with the same name.All existing
HttpField
s with the same name as the replacingHttpField
will be replaced by the givenHttpField
. If there are no fields with that name, the givenHttpField
is added to the returnedHttpFields.Mutable
instance.- Parameters:
fields
- theHttpFields
to copyreplaceField
- theHttpField
that replaces others with the same name- Returns:
- a new
HttpFields.Mutable
instance containing the givenHttpFields
and the given replacementHttpField
-
build
Returns a new
HttpFields.Mutable
instance containing a copy of all theHttpField
s of the givenHttpFields
, removing theHttpField
s with the given names.- Parameters:
fields
- theHttpFields
to copyremoveFields
- the names of the fields to remove- Returns:
- a new
HttpFields.Mutable
instance containing the givenHttpFields
without the fields with the given names
-
from
Returns an immutable
HttpFields
instance containing the givenHttpField
s.- Parameters:
fields
- theHttpField
s to be contained in the returned instance- Returns:
- a new immutable
HttpFields
instance with the givenHttpField
s
-
get
Supplies this instance, typically used to supply HTTP trailers.
- Specified by:
get
in interfaceSupplier<HttpFields>
- Returns:
- this instance
-
iterator
-
listIterator
- Returns:
- an iterator over the
HttpField
s in thisHttpFields
. - See Also:
-
listIterator
- Returns:
- an iterator over the
HttpField
s in thisHttpFields
starting at the given index. - See Also:
-
asImmutable
Returns an immutable copy of this
HttpFields
instance.- Returns:
- a new immutable copy of this
HttpFields
instance
-
asString
Returns the HTTP/1.1 string representation of the
HttpField
s of this instance.The format of each field is:
<name>: <value>\r\n
, and there will be an additional\r\n
after the last field, for example:Host: localhost\r\n Connection: close\r\n \r\n
- Returns:
- an HTTP/1.1 string representation of the
HttpField
s of this instance
-
contains
Returns whether this instance contains the given
HttpField
.The comparison of
HttpField
names is case-insensitive viaHttpField.isSameName(HttpField)
. The comparison of the field value is case-insensitive viaHttpField.contains(String)
. -
contains
Returns whether this instance contains the given
HttpHeader
with the given value.The comparison of the field value is case-insensitive via
HttpField.contains(String)
.- Parameters:
header
- the name of the field to search forvalue
- the value to search for- Returns:
- whether this instance contains the given
HttpHeader
with the given value
-
containsLast
Look for a value as the last value in a possible multivalued field. Parameters and specifically quality parameters are not considered.- Parameters:
header
- TheHttpHeader
type to search for.value
- The value to search for (case-insensitive)- Returns:
- True iff the value is contained in the field value entirely or as the last element of a quoted comma separated list.
- See Also:
-
contains
Returns whether this instance contains the given field name with the given value.
The comparison of field name is case-insensitive via
HttpField.is(String)
. The comparison of the field value is case-insensitive viaHttpField.contains(String)
.- Parameters:
name
- the case-insensitive field name to search forvalue
- the field value to search for- Returns:
- whether this instance contains the given field name with the given value
-
contains
Returns whether this instance contains the given field name.
- Parameters:
header
- the field name to search for- Returns:
- whether this instance contains the given field name
-
contains
Returns whether this instance contains at least one of the given field names.
- Parameters:
headers
- the field names to search among- Returns:
- whether this instance contains at least one of the given field names
-
contains
Returns whether this instance contains the given field name.
The comparison of field name is case-insensitive via
HttpField.is(String)
. If possible, it is more efficient to usecontains(HttpHeader)
.- Parameters:
name
- the case-insensitive field name to search for- Returns:
- whether this instance contains the given field name
- See Also:
-
get
Returns the encoded value of the first field with the given field name, or
null
if no such header is present.In case of multi-valued fields, the returned value is the encoded value, including commas and quotes, as returned by
HttpField.getValue()
.- Parameters:
header
- the field name to search for- Returns:
- the raw value of the first field with the given field name,
or
null
if no such header is present - See Also:
-
getLast
Returns the encoded value of the last field with the given field name, or
null
if no such header is present.In case of multi-valued fields, the returned value is the encoded value, including commas and quotes, as returned by
HttpField.getValue()
.- Parameters:
header
- the field name to search for- Returns:
- the raw value of the last field with the given field name,
or
null
if no such header is present - See Also:
-
get
Returns the encoded value of the first field with the given field name, or
null
if no such field is present.The comparison of field name is case-insensitive via
HttpField.is(String)
. If possible, it is more efficient to useget(HttpHeader)
.In case of multi-valued fields, the returned value is the encoded value, including commas and quotes, as returned by
HttpField.getValue()
.- Parameters:
name
- the case-insensitive field name to search for- Returns:
- the raw value of the first field with the given field name,
or
null
if no such field is present - See Also:
-
getCSV
Returns all the values of all the fields with the given field name.
In case of multi-valued fields, the multi-value of the field is split using
QuotedCSV
, taking into account the givenkeepQuotes
parameter.- Parameters:
header
- the field name to search forkeepQuotes
- whether the fields values should retain the quotes- Returns:
- a list of all the values of all the fields with the given name, or an empty list if no such field name is present
-
getCSV
Returns all the values of all the fields with the given field name.
The comparison of field name is case-insensitive via
HttpField.is(String)
.In case of multi-valued fields, the multi-value of the field is split using
QuotedCSV
, taking into account the givenkeepQuotes
parameter.- Parameters:
name
- the case-insensitive field name to search forkeepQuotes
- whether the fields values should retain the quotes- Returns:
- a list of all the values of all the fields with the given name, or an empty list if no such field name is present
-
getDateField
Returns the value of a date field as the number of milliseconds since the Unix Epoch, or -1 if no such field is present.
The comparison of field name is case-insensitive via
HttpField.is(String)
.- Parameters:
name
- the case-insensitive field name to search for- Returns:
- the value of the field as the number of milliseconds since Unix Epoch, or -1 if no such field is present
-
getDateField
Returns the value of a date field as the number of milliseconds since the Unix Epoch, or -1 if no such field is present.
- Parameters:
header
- the field name to search for- Returns:
- the value of the field as the number of milliseconds since Unix Epoch, or -1 if no such field is present
-
getField
Returns the
HttpField
at the givenindex
, ornull
if there is no field at the given index. -
getField
Returns the first
HttpField
with the given field name, ornull
if no such field is present.- Parameters:
header
- the field name to search for- Returns:
- the first
HttpField
with the given field name, ornull
if no such field is present
-
getField
Returns the first
HttpField
with the given field name, ornull
if no such field is present.The comparison of field name is case-insensitive via
HttpField.is(String)
.- Parameters:
name
- the case-insensitive field name to search for- Returns:
- the first
HttpField
with the given field name, ornull
if no such field is present
-
getFieldNames
Deprecated.- Returns:
- an enumeration of field names
-
getFieldNamesCollection
Returns a
Set
of the field names.Case-sensitivity of the field names is preserved.
- Returns:
- an immutable
Set
of the field names. Changes made to theHttpFields
after this call are not reflected in the set.
-
getFields
Returns all the
HttpField
s with the given field name.- Parameters:
header
- the field name to search for- Returns:
- a list of the
HttpField
s with the given field name, or an empty list if no such field name is present
-
getFields
Returns all the
HttpField
s with the given field name.The comparison of field name is case-insensitive via
HttpField.is(String)
.- Parameters:
name
- the case-insensitive field name to search for- Returns:
- a list of the
HttpField
s with the given field name, or an empty list if no such field name is present
-
getLongField
Returns the value of a field as a
long
value, or -1 if no such field is present.The comparison of field name is case-insensitive via
HttpField.is(String)
.- Parameters:
name
- the case-insensitive field name- Returns:
- the value of the field as a
long
, or -1 if no such field is present - Throws:
NumberFormatException
- if the value of the field cannot be converted to along
-
getLongField
Returns the value of a field as a
long
value, or -1 if no such field is present.- Parameters:
header
- the field name- Returns:
- the value of the field as a
long
, or -1 if no such field is present - Throws:
NumberFormatException
- if the value of the field cannot be converted to along
-
getQualityCSV
Returns all the values of all the fields with the given name, split and sorted in quality order using
QuotedQualityCSV
.- Parameters:
header
- the field name to search for- Returns:
- a list of all the values of all the fields with the given name, split and sorted in quality order, or an empty list if no such field name is present
-
getQualityCSV
Returns all the values of all the fields with the given name, split and sorted first in quality order and then optionally further sorted with the given function, using
QuotedQualityCSV
.- Parameters:
header
- the field name to search forsecondaryOrdering
- the secondary sort function, ornull
for no secondary sort- Returns:
- a list of all the values of all the fields with the given name, split and sorted in quality order and optionally further sorted with the given function, or an empty list if no such field name is present
-
getQualityCSV
Returns all the values of all the fields with the given name, split and sorted in quality order using
QuotedQualityCSV
.The comparison of field name is case-insensitive via
HttpField.is(String)
.- Parameters:
name
- the case-insensitive field name to search for- Returns:
- a list of all the values of all the fields with the given name, split and sorted in quality order, or an empty list if no such field name is present
-
getValues
Returns an
Enumeration
of the encoded values of all the fields with the given name.The comparison of field name is case-insensitive via
HttpField.is(String)
.In case of multi-valued fields, the returned value is the encoded value, including commas and quotes, as returned by
HttpField.getValue()
.- Parameters:
name
- the case-insensitive field name to search for- Returns:
- an
Enumeration
of the encoded values of all the fields with the given name
-
getValuesList
Returns a list of the encoded values of all the fields with the given name.
In case of multi-valued fields, the returned value is the encoded value, including commas and quotes, as returned by
HttpField.getValue()
.- Parameters:
header
- the field name to search for- Returns:
- a list of the encoded values of all the fields with the given name, or an empty list if no such field name is present
-
getValuesList
Returns a list of the encoded values of all the fields with the given name.
The comparison of field name is case-insensitive via
HttpField.is(String)
.In case of multi-valued fields, the returned value is the encoded value, including commas and quotes, as returned by
HttpField.getValue()
.- Parameters:
name
- the field name to search for- Returns:
- a list of the encoded values of all the fields with the given name, or an empty list if no such field name is present
-
isEqualTo
Returns whether this instance is equal to the given instance.
Returns
true
if and only if the two instances have the same number of fields, in the same order, and each field is equal, but makes no difference betweenHttpFields.Mutable
and non-HttpFields.Mutable
instances.- Parameters:
that
- theHttpFields
instance to compare to- Returns:
- whether the two instances are equal
-
size
default int size()- Returns:
- the number of
HttpField
s in this instance
-
stream
- Returns:
- a sequential stream of the
HttpField
s in this instance
-
getFieldNamesCollection()