Class HttpFields
This class is not synchronized as it is expected that modifications will only be performed by a single thread.
The cookie handling provided by this class is guided by the Servlet specification and RFC6265.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDeprecated.Initialize an empty HttpFields.HttpFields
(int capacity) Deprecated.Initialize an empty HttpFields.HttpFields
(HttpFields fields) Deprecated.Initialize HttpFields from copy. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Deprecated.Add to or set a field.void
Deprecated.void
add
(HttpFields fields) Deprecated.void
add
(HttpHeader header, String value) Deprecated.Add to or set a field.void
add
(HttpHeader header, HttpHeaderValue value) Deprecated.void
addAll
(HttpFields fields) Deprecated.boolean
Deprecated.Add comma separated values, but only if not already present.boolean
addCSV
(HttpHeader header, String... values) Deprecated.Add comma separated values, but only if not already present.void
addDateField
(String name, long date) Deprecated.Sets the value of a date field.void
clear()
Deprecated.void
computeField
(String name, BiFunction<String, List<HttpField>, HttpField> computeFn) Deprecated.Computes a single field for the given HTTP header name and for existing fields with the same name.void
computeField
(HttpHeader header, BiFunction<HttpHeader, List<HttpField>, HttpField> computeFn) Deprecated.Computes a single field for the given HttpHeader and for existing fields with the same header.boolean
Deprecated.boolean
Deprecated.boolean
contains
(HttpHeader header) Deprecated.boolean
contains
(HttpHeader header, String value) Deprecated.boolean
containsKey
(String name) Deprecated.boolean
Deprecated.Deprecated.get
(HttpHeader header) Deprecated.Deprecated.Get multiple field values of the same name as aQuotedCSV
getCSV
(HttpHeader header, boolean keepQuotes) Deprecated.Get multiple field values of the same name, split as aQuotedCSV
long
getDateField
(String name) Deprecated.Get a header as a date value.getField
(int index) Deprecated.Get a Field by index.Deprecated.getField
(HttpHeader header) Deprecated.Deprecated.Get enumeration of header _names.Deprecated.Get Collection of header names.Deprecated.getFields
(HttpHeader header) Deprecated.long
getLongField
(String name) Deprecated.Get a header as an long value.static Float
getQuality
(String value) Deprecated.getQualityCSV
(String name) Deprecated.Get multiple field values of the same name, split and sorted as aQuotedQualityCSV
getQualityCSV
(HttpHeader header) Deprecated.Get multiple field values of the same name, split and sorted as aQuotedQualityCSV
getQualityCSV
(HttpHeader header, ToIntFunction<String> secondaryOrdering) Deprecated.Get multiple field values of the same name, split and sorted as aQuotedQualityCSV
getStringField
(String name) Deprecated.getStringField
(HttpHeader header) Deprecated.Deprecated.Get multi headersDeprecated.getValuesList
(String name) Deprecated.Get multiple header of the same namegetValuesList
(HttpHeader header) Deprecated.Get multiple header of the same nameint
hashCode()
Deprecated.iterator()
Deprecated.Deprecated.void
Deprecated.Set a field.void
Deprecated.Set a field.void
Deprecated.void
put
(HttpHeader header, String value) Deprecated.Set a field.void
put
(HttpHeader header, HttpHeaderValue value) Deprecated.void
putDateField
(String name, long date) Deprecated.Sets the value of a date field.void
putDateField
(HttpHeader name, long date) Deprecated.Sets the value of a date field.void
putLongField
(String name, long value) Deprecated.Sets the value of an long field.void
putLongField
(HttpHeader name, long value) Deprecated.Sets the value of an long field.Deprecated.Deprecated.Remove a field.remove
(HttpHeader name) Deprecated.Remove a field.int
size()
Deprecated.stream()
Deprecated.static String
stripParameters
(String value) Deprecated.Get field value without parameters.toString()
Deprecated.static String
valueParameters
(String value, Map<String, String> parameters) Deprecated.Get field value parameters.Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
__separators
Deprecated.- See Also:
-
-
Constructor Details
-
HttpFields
public HttpFields()Deprecated.Initialize an empty HttpFields. -
HttpFields
public HttpFields(int capacity) Deprecated.Initialize an empty HttpFields.- Parameters:
capacity
- the capacity of the http fields
-
HttpFields
Deprecated.Initialize HttpFields from copy.- Parameters:
fields
- the fields to copy data from
-
-
Method Details
-
computeField
public void computeField(HttpHeader header, BiFunction<HttpHeader, List<HttpField>, HttpField> computeFn) Deprecated.Computes a single field for the given HttpHeader and for existing fields with the same header.
The compute function receives the field name and a list of fields with the same name so that their values can be used to compute the value of the field that is returned by the compute function. If the compute function returns
null
, the fields with the given name are removed.This method comes handy when you want to add an HTTP header if it does not exist, or add a value if the HTTP header already exists, similarly to
Map.compute(Object, BiFunction)
.This method can be used to
put
a new field (or blindly replace its value):httpFields.computeField("X-New-Header", (name, fields) -> new HttpField(name, "NewValue"));
This method can be used to coalesce many fields into one:
// Input: GET / HTTP/1.1 Host: localhost Cookie: foo=1 Cookie: bar=2,baz=3 User-Agent: Jetty // Computation: httpFields.computeField("Cookie", (name, fields) -> { // No cookies, nothing to do. if (fields == null) return null; // Coalesces all cookies. String coalesced = fields.stream() .flatMap(field -> Stream.of(field.getValues())) .collect(Collectors.joining(", ")); // Returns a single Cookie header with all cookies. return new HttpField(name, coalesced); } // Output: GET / HTTP/1.1 Host: localhost Cookie: foo=1, bar=2, baz=3 User-Agent: Jetty
This method can be used to replace a field:
httpFields.computeField("X-Length", (name, fields) -> { if (fields == null) return null; // Get any value among the X-Length headers. String length = fields.stream() .map(HttpField::getValue) .findAny() .orElse("0"); // Replace X-Length headers with X-Capacity header. return new HttpField("X-Capacity", length); });
This method can be used to remove a field:
httpFields.computeField("Connection", (name, fields) -> null);
- Parameters:
header
- the HTTP headercomputeFn
- the compute function
-
computeField
Deprecated.Computes a single field for the given HTTP header name and for existing fields with the same name.
- Parameters:
name
- the HTTP header namecomputeFn
- the compute function- See Also:
-
size
public int size()Deprecated. -
iterator
Deprecated. -
listIterator
Deprecated. -
stream
Deprecated. -
getFieldNamesCollection
Deprecated.Get Collection of header names.- Returns:
- the unique set of field names.
-
getFieldNames
Deprecated.Get enumeration of header _names. Returns an enumeration of strings representing the header _names for this request.- Returns:
- an enumeration of field names
-
getField
Deprecated.Get a Field by index.- Parameters:
index
- the field index- Returns:
- A Field value or null if the Field value has not been set
-
getField
Deprecated. -
getField
Deprecated. -
getFields
Deprecated. -
getFields
Deprecated. -
contains
Deprecated. -
contains
Deprecated. -
contains
Deprecated. -
contains
Deprecated. -
containsKey
Deprecated. -
getStringField
Deprecated. -
get
Deprecated. -
getStringField
Deprecated. -
get
Deprecated. -
getValuesList
Deprecated.Get multiple header of the same name- Parameters:
header
- the header- Returns:
- List the values
-
getValuesList
Deprecated.Get multiple header of the same name- Parameters:
name
- the case-insensitive field name- Returns:
- List the header values
-
addCSV
Deprecated.Add comma separated values, but only if not already present.- Parameters:
header
- The header to add the value(s) tovalues
- The value(s) to add- Returns:
- True if headers were modified
-
addCSV
Deprecated.Add comma separated values, but only if not already present.- Parameters:
name
- The header to add the value(s) tovalues
- The value(s) to add- Returns:
- True if headers were modified
-
getCSV
Deprecated.Get multiple field values of the same name, split as aQuotedCSV
- Parameters:
header
- The headerkeepQuotes
- True if the fields are kept quoted- Returns:
- List the values with OWS stripped
-
getCSV
Deprecated.Get multiple field values of the same name as aQuotedCSV
- Parameters:
name
- the case-insensitive field namekeepQuotes
- True if the fields are kept quoted- Returns:
- List the values with OWS stripped
-
getQualityCSV
Deprecated.Get multiple field values of the same name, split and sorted as aQuotedQualityCSV
- Parameters:
header
- The header- Returns:
- List the values in quality order with the q param and OWS stripped
-
getQualityCSV
Deprecated.Get multiple field values of the same name, split and sorted as aQuotedQualityCSV
- Parameters:
header
- The headersecondaryOrdering
- Function to apply an ordering other than specified by quality- Returns:
- List the values in quality order with the q param and OWS stripped
-
getQualityCSV
Deprecated.Get multiple field values of the same name, split and sorted as aQuotedQualityCSV
- Parameters:
name
- the case-insensitive field name- Returns:
- List the values in quality order with the q param and OWS stripped
-
getValues
Deprecated.Get multi headers- Parameters:
name
- the case-insensitive field name- Returns:
- Enumeration of the values
-
getValues
Deprecated.Get multi field values with separator. The multiple values can be represented as separate headers of the same name, or by a single header using the separator(s), or a combination of both. Separators may be quoted.- Parameters:
name
- the case-insensitive field nameseparators
- String of separators.- Returns:
- Enumeration of the values, or null if no such header.
-
put
Deprecated. -
put
Deprecated.Set a field.- Parameters:
name
- the name of the fieldvalue
- the value of the field. If null the field is cleared.
-
put
Deprecated. -
put
Deprecated.Set a field.- Parameters:
header
- the header name of the fieldvalue
- the value of the field. If null the field is cleared.
-
put
Deprecated.Set a field.- Parameters:
name
- the name of the fieldlist
- the List value of the field. If null the field is cleared.
-
add
Deprecated.Add to or set a field. If the field is allowed to have multiple values, add will add multiple headers of the same name.- Parameters:
name
- the name of the fieldvalue
- the value of the field.
-
add
Deprecated. -
add
Deprecated.Add to or set a field. If the field is allowed to have multiple values, add will add multiple headers of the same name.- Parameters:
header
- the headervalue
- the value of the field.
-
remove
Deprecated.Remove a field.- Parameters:
name
- the field to remove- Returns:
- the header that was removed
-
remove
Deprecated.Remove a field.- Parameters:
name
- the field to remove- Returns:
- the header that was removed
-
getLongField
Deprecated.Get a header as an long value. Returns the value of an integer field or -1 if not found. The case of the field name is ignored.- Parameters:
name
- the case-insensitive field name- Returns:
- the value of the field as a long
- Throws:
NumberFormatException
- If bad long found
-
getDateField
Deprecated.Get a header as a date value. Returns the value of a date field, or -1 if not found. The case of the field name is ignored.- Parameters:
name
- the case-insensitive field name- Returns:
- the value of the field as a number of milliseconds since unix epoch
-
putLongField
Deprecated.Sets the value of an long field.- Parameters:
name
- the field namevalue
- the field long value
-
putLongField
Deprecated.Sets the value of an long field.- Parameters:
name
- the field namevalue
- the field long value
-
putDateField
Deprecated.Sets the value of a date field.- Parameters:
name
- the field namedate
- the field date value
-
putDateField
Deprecated.Sets the value of a date field.- Parameters:
name
- the field namedate
- the field date value
-
addDateField
Deprecated.Sets the value of a date field.- Parameters:
name
- the field namedate
- the field date value
-
hashCode
public int hashCode()Deprecated. -
equals
Deprecated. -
toString
Deprecated. -
clear
public void clear()Deprecated. -
add
Deprecated. -
addAll
Deprecated. -
add
Deprecated.Add fields from another HttpFields instance. Single valued fields are replaced, while all others are added.- Parameters:
fields
- the fields to add
-
stripParameters
Deprecated.Get field value without parameters. Some field values can have parameters. This method separates the value from the parameters and optionally populates a map with the parameters. For example:FieldName : Value ; param1=val1 ; param2=val2
- Parameters:
value
- The Field value, possibly with parameters.- Returns:
- The value.
-
valueParameters
Deprecated.Get field value parameters. Some field values can have parameters. This method separates the value from the parameters and optionally populates a map with the parameters. For example:FieldName : Value ; param1=val1 ; param2=val2
- Parameters:
value
- The Field value, possibly with parameters.parameters
- A map to populate with the parameters, or null- Returns:
- The value.
-
getQuality
Deprecated. -
qualityList
Deprecated.List values in quality order.- Parameters:
e
- Enumeration of values with quality parameters- Returns:
- values in quality order.
-