Class HttpFields
- java.lang.Object
-
- org.eclipse.jetty.http.HttpFields
-
- All Implemented Interfaces:
java.lang.Iterable<HttpField>
@Deprecated(since="2021-05-27") public class HttpFields extends java.lang.Object implements java.lang.Iterable<HttpField>
Deprecated.The Eclipse Jetty and Apache Felix Http Jetty packages are no longer supported.HTTP Fields. A collection of HTTP header and or Trailer fields.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 Modifier and Type Field Description static java.lang.String
__separators
Deprecated.
-
Constructor Summary
Constructors Constructor Description HttpFields()
Deprecated.Initialize an empty HttpFields.HttpFields(int capacity)
Deprecated.Initialize an empty HttpFields.HttpFields(HttpFields fields)
Deprecated.Initialize HttpFields from copy.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
add(java.lang.String name, java.lang.String value)
Deprecated.Add to or set a field.void
add(HttpField field)
Deprecated.void
add(HttpFields fields)
Deprecated.void
add(HttpHeader header, java.lang.String value)
Deprecated.Add to or set a field.void
add(HttpHeader header, HttpHeaderValue value)
Deprecated.void
addAll(HttpFields fields)
Deprecated.boolean
addCSV(java.lang.String name, java.lang.String... values)
Deprecated.Add comma separated values, but only if not already present.boolean
addCSV(HttpHeader header, java.lang.String... values)
Deprecated.Add comma separated values, but only if not already present.void
addDateField(java.lang.String name, long date)
Deprecated.Sets the value of a date field.void
clear()
Deprecated.void
computeField(java.lang.String name, java.util.function.BiFunction<java.lang.String,java.util.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, java.util.function.BiFunction<HttpHeader,java.util.List<HttpField>,HttpField> computeFn)
Deprecated.Computes a single field for the given HttpHeader and for existing fields with the same header.boolean
contains(java.lang.String name, java.lang.String value)
Deprecated.boolean
contains(HttpField field)
Deprecated.boolean
contains(HttpHeader header)
Deprecated.boolean
contains(HttpHeader header, java.lang.String value)
Deprecated.boolean
containsKey(java.lang.String name)
Deprecated.boolean
equals(java.lang.Object o)
Deprecated.java.lang.String
get(java.lang.String header)
Deprecated.java.lang.String
get(HttpHeader header)
Deprecated.java.util.List<java.lang.String>
getCSV(java.lang.String name, boolean keepQuotes)
Deprecated.Get multiple field values of the same name as aQuotedCSV
java.util.List<java.lang.String>
getCSV(HttpHeader header, boolean keepQuotes)
Deprecated.Get multiple field values of the same name, split as aQuotedCSV
long
getDateField(java.lang.String name)
Deprecated.Get a header as a date value.HttpField
getField(int index)
Deprecated.Get a Field by index.HttpField
getField(java.lang.String name)
Deprecated.HttpField
getField(HttpHeader header)
Deprecated.java.util.Enumeration<java.lang.String>
getFieldNames()
Deprecated.Get enumeration of header _names.java.util.Set<java.lang.String>
getFieldNamesCollection()
Deprecated.Get Collection of header names.java.util.List<HttpField>
getFields(java.lang.String name)
Deprecated.java.util.List<HttpField>
getFields(HttpHeader header)
Deprecated.long
getLongField(java.lang.String name)
Deprecated.Get a header as an long value.static java.lang.Float
getQuality(java.lang.String value)
Deprecated.java.util.List<java.lang.String>
getQualityCSV(java.lang.String name)
Deprecated.Get multiple field values of the same name, split and sorted as aQuotedQualityCSV
java.util.List<java.lang.String>
getQualityCSV(HttpHeader header)
Deprecated.Get multiple field values of the same name, split and sorted as aQuotedQualityCSV
java.util.List<java.lang.String>
getQualityCSV(HttpHeader header, java.util.function.ToIntFunction<java.lang.String> secondaryOrdering)
Deprecated.Get multiple field values of the same name, split and sorted as aQuotedQualityCSV
java.lang.String
getStringField(java.lang.String name)
Deprecated.java.lang.String
getStringField(HttpHeader header)
Deprecated.java.util.Enumeration<java.lang.String>
getValues(java.lang.String name)
Deprecated.Get multi headersjava.util.Enumeration<java.lang.String>
getValues(java.lang.String name, java.lang.String separators)
Deprecated.java.util.List<java.lang.String>
getValuesList(java.lang.String name)
Deprecated.Get multiple header of the same namejava.util.List<java.lang.String>
getValuesList(HttpHeader header)
Deprecated.Get multiple header of the same nameint
hashCode()
Deprecated.java.util.Iterator<HttpField>
iterator()
Deprecated.java.util.ListIterator<HttpField>
listIterator()
Deprecated.void
put(java.lang.String name, java.lang.String value)
Deprecated.Set a field.void
put(java.lang.String name, java.util.List<java.lang.String> list)
Deprecated.Set a field.void
put(HttpField field)
Deprecated.void
put(HttpHeader header, java.lang.String value)
Deprecated.Set a field.void
put(HttpHeader header, HttpHeaderValue value)
Deprecated.void
putDateField(java.lang.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(java.lang.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.static java.util.List<java.lang.String>
qualityList(java.util.Enumeration<java.lang.String> e)
Deprecated.HttpField
remove(java.lang.String name)
Deprecated.Remove a field.HttpField
remove(HttpHeader name)
Deprecated.Remove a field.int
size()
Deprecated.java.util.stream.Stream<HttpField>
stream()
Deprecated.static java.lang.String
stripParameters(java.lang.String value)
Deprecated.Get field value without parameters.java.lang.String
toString()
Deprecated.static java.lang.String
valueParameters(java.lang.String value, java.util.Map<java.lang.String,java.lang.String> parameters)
Deprecated.Get field value parameters.
-
-
-
Field Detail
-
__separators
@Deprecated public static final java.lang.String __separators
Deprecated.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
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
public HttpFields(HttpFields fields)
Deprecated.Initialize HttpFields from copy.- Parameters:
fields
- the fields to copy data from
-
-
Method Detail
-
computeField
public void computeField(HttpHeader header, java.util.function.BiFunction<HttpHeader,java.util.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
public void computeField(java.lang.String name, java.util.function.BiFunction<java.lang.String,java.util.List<HttpField>,HttpField> computeFn)
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:
computeField(HttpHeader, BiFunction)
-
size
public int size()
Deprecated.
-
iterator
public java.util.Iterator<HttpField> iterator()
Deprecated.- Specified by:
iterator
in interfacejava.lang.Iterable<HttpField>
-
listIterator
public java.util.ListIterator<HttpField> listIterator()
Deprecated.
-
stream
public java.util.stream.Stream<HttpField> stream()
Deprecated.
-
getFieldNamesCollection
public java.util.Set<java.lang.String> getFieldNamesCollection()
Deprecated.Get Collection of header names.- Returns:
- the unique set of field names.
-
getFieldNames
public java.util.Enumeration<java.lang.String> 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
public HttpField getField(int index)
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
public HttpField getField(HttpHeader header)
Deprecated.
-
getField
public HttpField getField(java.lang.String name)
Deprecated.
-
getFields
public java.util.List<HttpField> getFields(HttpHeader header)
Deprecated.
-
getFields
public java.util.List<HttpField> getFields(java.lang.String name)
Deprecated.
-
contains
public boolean contains(HttpField field)
Deprecated.
-
contains
public boolean contains(HttpHeader header, java.lang.String value)
Deprecated.
-
contains
public boolean contains(java.lang.String name, java.lang.String value)
Deprecated.
-
contains
public boolean contains(HttpHeader header)
Deprecated.
-
containsKey
public boolean containsKey(java.lang.String name)
Deprecated.
-
getStringField
@Deprecated public java.lang.String getStringField(HttpHeader header)
Deprecated.
-
get
public java.lang.String get(HttpHeader header)
Deprecated.
-
getStringField
@Deprecated public java.lang.String getStringField(java.lang.String name)
Deprecated.
-
get
public java.lang.String get(java.lang.String header)
Deprecated.
-
getValuesList
public java.util.List<java.lang.String> getValuesList(HttpHeader header)
Deprecated.Get multiple header of the same name- Parameters:
header
- the header- Returns:
- List the values
-
getValuesList
public java.util.List<java.lang.String> getValuesList(java.lang.String name)
Deprecated.Get multiple header of the same name- Parameters:
name
- the case-insensitive field name- Returns:
- List the header values
-
addCSV
public boolean addCSV(HttpHeader header, java.lang.String... values)
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
public boolean addCSV(java.lang.String name, java.lang.String... values)
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
public java.util.List<java.lang.String> getCSV(HttpHeader header, boolean keepQuotes)
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
public java.util.List<java.lang.String> getCSV(java.lang.String name, boolean keepQuotes)
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
public java.util.List<java.lang.String> getQualityCSV(HttpHeader header)
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
public java.util.List<java.lang.String> getQualityCSV(HttpHeader header, java.util.function.ToIntFunction<java.lang.String> secondaryOrdering)
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
public java.util.List<java.lang.String> getQualityCSV(java.lang.String name)
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
public java.util.Enumeration<java.lang.String> getValues(java.lang.String name)
Deprecated.Get multi headers- Parameters:
name
- the case-insensitive field name- Returns:
- Enumeration of the values
-
getValues
@Deprecated public java.util.Enumeration<java.lang.String> getValues(java.lang.String name, java.lang.String separators)
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
public void put(HttpField field)
Deprecated.
-
put
public void put(java.lang.String name, java.lang.String value)
Deprecated.Set a field.- Parameters:
name
- the name of the fieldvalue
- the value of the field. If null the field is cleared.
-
put
public void put(HttpHeader header, HttpHeaderValue value)
Deprecated.
-
put
public void put(HttpHeader header, java.lang.String value)
Deprecated.Set a field.- Parameters:
header
- the header name of the fieldvalue
- the value of the field. If null the field is cleared.
-
put
public void put(java.lang.String name, java.util.List<java.lang.String> list)
Deprecated.Set a field.- Parameters:
name
- the name of the fieldlist
- the List value of the field. If null the field is cleared.
-
add
public void add(java.lang.String name, java.lang.String value)
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
public void add(HttpHeader header, HttpHeaderValue value)
Deprecated.
-
add
public void add(HttpHeader header, java.lang.String value)
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
public HttpField remove(HttpHeader name)
Deprecated.Remove a field.- Parameters:
name
- the field to remove- Returns:
- the header that was removed
-
remove
public HttpField remove(java.lang.String name)
Deprecated.Remove a field.- Parameters:
name
- the field to remove- Returns:
- the header that was removed
-
getLongField
public long getLongField(java.lang.String name) throws java.lang.NumberFormatException
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:
java.lang.NumberFormatException
- If bad long found
-
getDateField
public long getDateField(java.lang.String name)
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
public void putLongField(HttpHeader name, long value)
Deprecated.Sets the value of an long field.- Parameters:
name
- the field namevalue
- the field long value
-
putLongField
public void putLongField(java.lang.String name, long value)
Deprecated.Sets the value of an long field.- Parameters:
name
- the field namevalue
- the field long value
-
putDateField
public void putDateField(HttpHeader name, long date)
Deprecated.Sets the value of a date field.- Parameters:
name
- the field namedate
- the field date value
-
putDateField
public void putDateField(java.lang.String name, long date)
Deprecated.Sets the value of a date field.- Parameters:
name
- the field namedate
- the field date value
-
addDateField
public void addDateField(java.lang.String name, long date)
Deprecated.Sets the value of a date field.- Parameters:
name
- the field namedate
- the field date value
-
hashCode
public int hashCode()
Deprecated.- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
Deprecated.- Overrides:
equals
in classjava.lang.Object
-
toString
public java.lang.String toString()
Deprecated.- Overrides:
toString
in classjava.lang.Object
-
clear
public void clear()
Deprecated.
-
add
public void add(HttpField field)
Deprecated.
-
addAll
public void addAll(HttpFields fields)
Deprecated.
-
add
@Deprecated public void add(HttpFields fields)
Deprecated.Add fields from another HttpFields instance. Single valued fields are replaced, while all others are added.- Parameters:
fields
- the fields to add
-
stripParameters
public static java.lang.String stripParameters(java.lang.String value)
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
public static java.lang.String valueParameters(java.lang.String value, java.util.Map<java.lang.String,java.lang.String> parameters)
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 public static java.lang.Float getQuality(java.lang.String value)
Deprecated.
-
qualityList
@Deprecated public static java.util.List<java.lang.String> qualityList(java.util.Enumeration<java.lang.String> e)
Deprecated.List values in quality order.- Parameters:
e
- Enumeration of values with quality parameters- Returns:
- values in quality order.
-
-