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
An ordered collection of HttpFields 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 HttpFields need to looked up, it may be
better to use an Iterator to find multiple fields in a single iteration.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classDeprecated, for removal: This API element is subject to removal in a future version.static interfaceA mutable version ofHttpFields.static classDeprecated, for removal: This API element is subject to removal in a future version. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final HttpFieldA constantHttpFieldfor the HTTP header:static final HttpFieldA constantHttpFieldfor the HTTP header:static final HttpFieldA constantHttpFieldfor the HTTP header:static final HttpFieldsA constant for an immutable and emptyHttpFields.static final HttpFieldA constantHttpFieldfor the HTTP header: -
Method Summary
Modifier and TypeMethodDescriptiondefault HttpFieldsReturns an immutable copy of thisHttpFieldsinstance.asMap(HttpFields fields) Wraps an instance ofHttpFieldsas aMap.default StringasString()Returns the HTTP/1.1 string representation of theHttpFields of this instance.static HttpFields.Mutablebuild()Returns an emptyHttpFields.Mutableinstance.static HttpFields.Mutablebuild(int capacity) Returns an emptyHttpFields.Mutableinstance with the given initialcapacity.static HttpFields.Mutablebuild(HttpFields fields) Returns a newHttpFields.Mutableinstance containing a copy of all theHttpFields of the givenHttpFieldsparameter.static HttpFields.Mutablebuild(HttpFields fields, EnumSet<HttpHeader> removeFields) Returns a newHttpFields.Mutableinstance containing a copy of all theHttpFields of the givenHttpFields, removing theHttpFields with the given names.static HttpFields.Mutablebuild(HttpFields fields, HttpField replaceField) Returns a newHttpFields.Mutableinstance containing a copy of all theHttpFields of the givenHttpFields, replacing with the givenHttpFieldall the fieldsHttpFields with the same name.default booleanReturns whether this instance contains the given field name.default booleanReturns whether this instance contains the given field name with the given value.default booleancontains(EnumSet<HttpHeader> headers) Returns whether this instance contains at least one of the given field names.default booleanReturns whether this instance contains the givenHttpField.default booleancontains(HttpHeader header) Returns whether this instance contains the given field name.default booleancontains(HttpHeader header, String value) Returns whether this instance contains the givenHttpHeaderwith the given value.default booleancontainsLast(HttpHeader header, String value) Look for a value as the last value in a possible multivalued field.static HttpFieldsReturns an immutableHttpFieldsinstance containing the givenHttpFields.default HttpFieldsget()Supplies this instance, typically used to supply HTTP trailers.default StringReturns the encoded value of the first field with the given field name, ornullif no such field is present.default Stringget(HttpHeader header) Returns the encoded value of the first field with the given field name, ornullif 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 longgetDateField(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 longgetDateField(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 HttpFieldgetField(int index) default HttpFieldReturns the firstHttpFieldwith the given field name, ornullif no such field is present.default HttpFieldgetField(HttpHeader header) Returns the firstHttpFieldwith the given field name, ornullif no such field is present.default Enumeration<String> Deprecated.Returns aSetof the field names.Returns all theHttpFields with the given field name.getFields(HttpHeader header) Returns all theHttpFields with the given field name.default StringgetLast(HttpHeader header) Returns the encoded value of the last field with the given field name, ornullif no such header is present.default longgetLongField(String name) Returns the value of a field as alongvalue, or -1 if no such field is present.default longgetLongField(HttpHeader header) Returns the value of a field as alongvalue, 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 anEnumerationof 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 booleanisEqualTo(HttpFields that) Returns whether this instance is equal to the given instance.iterator()default ListIterator<HttpField> listIterator(int index) default intsize()stream()Methods inherited from interface Iterable
forEach, spliterator
-
Field Details
-
EXPIRES_01JAN1970
-
CONNECTION_CLOSE
-
CONNECTION_KEEPALIVE
-
CONTENT_LENGTH_0
-
EMPTY
A constant for an immutable and empty
HttpFields.
-
-
Method Details
-
build
Returns an empty
HttpFields.Mutableinstance.- Returns:
- an empty
HttpFields.Mutableinstance
-
build
Returns an empty
HttpFields.Mutableinstance with the given initialcapacity.The given
capacityindicates the initial capacity of the storage for theHttpFields.When the capacity is exceeded, the storage is resized to accommodate the additional
HttpFields.- Parameters:
capacity- the initial capacity of the storage for theHttpFields- Returns:
- an empty instance with the given initial
capacity
-
build
Returns a new
HttpFields.Mutableinstance containing a copy of all theHttpFields of the givenHttpFieldsparameter.- Parameters:
fields- theHttpFieldsto copy- Returns:
- a new
HttpFields.Mutableinstance containing a copy of the givenHttpFields
-
build
Returns a new
HttpFields.Mutableinstance containing a copy of all theHttpFields of the givenHttpFields, replacing with the givenHttpFieldall the fieldsHttpFields with the same name.All existing
HttpFields with the same name as the replacingHttpFieldwill be replaced by the givenHttpField. If there are no fields with that name, the givenHttpFieldis added to the returnedHttpFields.Mutableinstance.- Parameters:
fields- theHttpFieldsto copyreplaceField- theHttpFieldthat replaces others with the same name- Returns:
- a new
HttpFields.Mutableinstance containing the givenHttpFieldsand the given replacementHttpField
-
build
Returns a new
HttpFields.Mutableinstance containing a copy of all theHttpFields of the givenHttpFields, removing theHttpFields with the given names.- Parameters:
fields- theHttpFieldsto copyremoveFields- the names of the fields to remove- Returns:
- a new
HttpFields.Mutableinstance containing the givenHttpFieldswithout the fields with the given names
-
from
Returns an immutable
HttpFieldsinstance containing the givenHttpFields.- Parameters:
fields- theHttpFields to be contained in the returned instance- Returns:
- a new immutable
HttpFieldsinstance with the givenHttpFields
-
get
Supplies this instance, typically used to supply HTTP trailers.
- Specified by:
getin interfaceSupplier<HttpFields>- Returns:
- this instance
-
iterator
-
listIterator
- Returns:
- an iterator over the
HttpFields in thisHttpFields. - See Also:
-
listIterator
- Returns:
- an iterator over the
HttpFields in thisHttpFieldsstarting at the given index. - See Also:
-
asImmutable
Returns an immutable copy of this
HttpFieldsinstance.- Returns:
- a new immutable copy of this
HttpFieldsinstance
-
asString
Returns the HTTP/1.1 string representation of the
HttpFields of this instance.The format of each field is:
<name>: <value>\r\n, and there will be an additional\r\nafter the last field, for example:Host: localhost\r\n Connection: close\r\n \r\n- Returns:
- an HTTP/1.1 string representation of the
HttpFields of this instance
-
contains
Returns whether this instance contains the given
HttpField.The comparison of
HttpFieldnames 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
HttpHeaderwith 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
HttpHeaderwith 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- TheHttpHeadertype 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
nullif 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
nullif no such header is present - See Also:
-
getLast
Returns the encoded value of the last field with the given field name, or
nullif 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
nullif no such header is present - See Also:
-
get
Returns the encoded value of the first field with the given field name, or
nullif 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
nullif 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 givenkeepQuotesparameter.- 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 givenkeepQuotesparameter.- 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
-
getField
-
getField
Returns the first
HttpFieldwith the given field name, ornullif 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
HttpFieldwith the given field name, ornullif no such field is present
-
getFieldNames
Deprecated.- Returns:
- an enumeration of field names
-
getFieldNamesCollection
-
getFields
-
getFields
Returns all the
HttpFields 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
HttpFields 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
longvalue, 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
longvalue, 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, ornullfor 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
Enumerationof 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
Enumerationof 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
trueif 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.Mutableand non-HttpFields.Mutableinstances.- Parameters:
that- theHttpFieldsinstance to compare to- Returns:
- whether the two instances are equal
-
size
default int size()- Returns:
- the number of
HttpFields in this instance
-
asMap
Wraps an instance of
HttpFieldsas aMap.If the provided
HttpFieldsis an instance ofHttpFields.Mutablethen changes to theMapwill be reflected in the underlyingHttpFields. Otherwise, any modification to theMapwill throwUnsupportedOperationException.- Parameters:
fields- theHttpFieldsto convert to aMap.- Returns:
- an
Maprepresenting the contents of theHttpFields.
-
stream
-
getFieldNamesCollection()