Top Description Inners Fields Constructors Methods
org.eclipse.jetty.http

public Class HttpField

extends Object
Class Inheritance
Known Direct Subclasses
org.eclipse.jetty.http.HttpField.IntValueHttpField, org.eclipse.jetty.http.HttpField.LongValueHttpField, org.eclipse.jetty.http.HttpField.MultiHttpField, org.eclipse.jetty.http.PreEncodedHttpField, org.eclipse.jetty.http.HostPortHttpField
Imports
java.util.Iterator, .List, .Map, .Objects, org.eclipse.jetty.util.QuotedStringTokenizer, .StringUtil

An immutable class representing an HTTP header or trailer.

HttpField has a case-insensitive name and case sensitive value, and may be multi-valued with each value separated by a comma.

See Also
HttpFields

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
HttpField.IntValueHttpField

A specialized HttpField whose value is an int.

public static class
HttpField.LongValueHttpField

A specialized HttpField whose value is a long.

pack-priv static class

Field Summary

Modifier and TypeField and Description
private int
private final HttpHeader
private final String
private final String
public static final QuotedStringTokenizer
NAME_VALUE_TOKENIZER

A constant QuotedStringTokenizer configured for quoting/tokenizing a single parameter as defined by RFC9110

public static final QuotedStringTokenizer
PARAMETER_TOKENIZER

A constant QuotedStringTokenizer configured for quoting/tokenizing parameters lists as defined by RFC9110

private static final String

Constructor Summary

AccessConstructor and Description
public
HttpField(HttpHeader
the HttpHeader referencing a well-known HTTP header name; may be null in case of an unknown or custom HTTP header name
header
,
String
the field name; if null, then HttpHeader#asString() is used
name
,
String
the field value; if null, the empty string will be used
value
)

Creates a new HttpField with the given HttpHeader, name string and value string.

public
HttpField(HttpHeader
the non-null HttpHeader referencing a well-known HTTP header name
header
,
String
the field value; if null, the empty string will be used
value
)

Creates a new HttpField with the given HttpHeader and value string.

public
HttpField(HttpHeader
the non-null HttpHeader referencing a well-known HTTP header name
header
,
HttpHeaderValue
the field value; if null, the empty string will be used
value
)

Creates a new HttpField with the given HttpHeader and value.

public
HttpField(String
the non-null field name
name
,
String
the field value; if null, the empty string will be used
value
)

Creates a new HttpField with the given name string and value string.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

whether this field value, possibly multi-valued, contains the specified search string
contains
(String
the string to search for
search
)

Returns whether this field value, possibly multi-valued, contains the specified search string, case-insensitively.

public static boolean

Returns:

whether the given value, possibly multi-valued, contains the specified search string
contains
(String
the value string to search into
value
,
String
the string to search for
search
)

Returns whether the given value, possibly multi-valued, contains the specified search string, case-insensitively.

public boolean

Returns:

True iff the value is contained in the field value entirely or as the last element of a quoted comma separated list.
containsLast
(String
Values to search for (case-insensitive)
search
)

Look for a value as the last value in a possible multivalued field Parameters and specifically quality parameters are not considered.

public static boolean

Returns:

True iff the value is contained in the field value entirely or as the last element of a quoted comma separated list.
containsLast
(String
The field value to search in.
value
,
String
Values to search for (case-insensitive)
search
)

Look for the last value in a possible multivalued field Parameters and specifically quality parameters are not considered.

public boolean
equals(Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public HttpHeader

Returns:

the HttpHeader of this field, or null
getHeader
()

Get the HttpHeader of this field, or null.

public int

Returns:

the value of this field as an int
getIntValue
()

public long

Returns:

the value of this field as an long
getLongValue
()

public String

Returns:

the field name in lower-case
getLowerCaseName
()

Get the field name in lower-case.

public String

Returns:

the field name
getName
()

Get the field name.

public String

Returns:

the field value
getValue
()

Get the field value.

public List<String>

Returns:

a list of the field values
getValueList
()

Returns a list of the field values.

public static String

Returns:

the field value without parameters
getValueParameters
(String
the field value, possibly with parameters
valueParams
,
Map<String, String>
An output map to populate with the parameters, or null to strip the parameters
parameters
)

Returns the field value and its parameters.

public String[]

Returns:

the field values as a String[]
getValues
()

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
public boolean

Returns:

whether this field name is the same as the given string
is
(String
the field name to compare to
name
)

Returns whether this field name is the same as the given string.

public boolean

Returns:

whether this field has the same name as the given field
isSameName
(HttpField
the field to compare the name to
field
)

Returns whether this field has the same name as the given field.

private int
public static String

Returns:

the field value without parameters
stripParameters
(String
the field value, possibly with parameters
value
)

Returns the field value, stripped of its parameters.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public static String
valueParameters(String value, Map<String, String> parameters)

Deprecated use getValueParameters(String, Map) instead
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

_hashback to summary
private int _hash
_headerback to summary
private final HttpHeader _header
_nameback to summary
private final String _name
_valueback to summary
private final String _value
NAME_VALUE_TOKENIZERback to summary
public static final QuotedStringTokenizer NAME_VALUE_TOKENIZER

A constant QuotedStringTokenizer configured for quoting/tokenizing a single parameter as defined by RFC9110

PARAMETER_TOKENIZERback to summary
public static final QuotedStringTokenizer PARAMETER_TOKENIZER

A constant QuotedStringTokenizer configured for quoting/tokenizing parameters lists as defined by RFC9110

ZERO_QUALITYback to summary
private static final String ZERO_QUALITY

Constructor Detail

HttpFieldback to summary
public HttpField(HttpHeader header, String name, String value)

Creates a new HttpField with the given HttpHeader, name string and value string.

A null field value may be passed as parameter, and will be converted to the empty string. This allows the direct constructions of fields that have no value, and/or HttpField subclasses that override getValue().

Parameters
header:HttpHeader

the HttpHeader referencing a well-known HTTP header name; may be null in case of an unknown or custom HTTP header name

name:String

the field name; if null, then HttpHeader#asString() is used

value:String

the field value; if null, the empty string will be used

HttpFieldback to summary
public HttpField(HttpHeader header, String value)

Creates a new HttpField with the given HttpHeader and value string.

Parameters
header:HttpHeader

the non-null HttpHeader referencing a well-known HTTP header name

value:String

the field value; if null, the empty string will be used

HttpFieldback to summary
public HttpField(HttpHeader header, HttpHeaderValue value)

Creates a new HttpField with the given HttpHeader and value.

Parameters
header:HttpHeader

the non-null HttpHeader referencing a well-known HTTP header name

value:HttpHeaderValue

the field value; if null, the empty string will be used

HttpFieldback to summary
public HttpField(String name, String value)

Creates a new HttpField with the given name string and value string.

Parameters
name:String

the non-null field name

value:String

the field value; if null, the empty string will be used

Method Detail

containsback to summary
public boolean contains(String search)

Returns whether this field value, possibly multi-valued, contains the specified search string, case-insensitively.

Only values, and not parameters, are compared with the search string.

Parameters
search:String

the string to search for

Returns:boolean

whether this field value, possibly multi-valued, contains the specified search string

containsback to summary
public static boolean contains(String value, String search)

Returns whether the given value, possibly multi-valued, contains the specified search string, case-insensitively.

Only values, and not parameters, are compared with the search string.

Parameters
value:String

the value string to search into

search:String

the string to search for

Returns:boolean

whether the given value, possibly multi-valued, contains the specified search string

containsLastback to summary
public boolean containsLast(String search)

Look for a value as the last value in a possible multivalued field Parameters and specifically quality parameters are not considered.

Parameters
search:String

Values to search for (case-insensitive)

Returns:boolean

True iff the value is contained in the field value entirely or as the last element of a quoted comma separated list.

containsLastback to summary
public static boolean containsLast(String value, String search)

Look for the last value in a possible multivalued field Parameters and specifically quality parameters are not considered.

Parameters
value:String

The field value to search in.

search:String

Values to search for (case-insensitive)

Returns:boolean

True iff the value is contained in the field value entirely or as the last element of a quoted comma separated list.

equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getHeaderback to summary
public HttpHeader getHeader()

Get the HttpHeader of this field, or null.

Returns:HttpHeader

the HttpHeader of this field, or null

getIntValueback to summary
public int getIntValue()
Returns:int

the value of this field as an int

Exceptions
NumberFormatException:
if the value cannot be parsed as an int
getLongValueback to summary
public long getLongValue()
Returns:long

the value of this field as an long

Exceptions
NumberFormatException:
if the value cannot be parsed as an long
getLowerCaseNameback to summary
public String getLowerCaseName()

Get the field name in lower-case.

Returns:String

the field name in lower-case

getNameback to summary
public String getName()

Get the field name.

Returns:String

the field name

getValueback to summary
public String getValue()

Get the field value.

Returns:String

the field value

getValueListback to summary
public List<String> getValueList()

Returns a list of the field values.

If the field value is multi-valued, the encoded field value is split into multiple values using QuotedCSV and the different values returned in a list.

If the field value is single-valued, the value is wrapped into a list.

Returns:List<String>

a list of the field values

getValueParametersback to summary
public static String getValueParameters(String valueParams, Map<String, String> parameters)

Returns the field value and its parameters.

A field value may have parameters, typically separated by ;, for example

Content-Type: text/plain; charset=UTF-8
Accept: text/html, text/plain; q=0.5
Parameters
valueParams:String

the field value, possibly with parameters

parameters:Map<String, String>

An output map to populate with the parameters, or null to strip the parameters

Returns:String

the field value without parameters

See Also
stripParameters(String)
getValuesback to summary
public String[] getValues()
Returns:String[]

the field values as a String[]

See Also
getValueList()
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override
isback to summary
public boolean is(String name)

Returns whether this field name is the same as the given string.

The comparison of field name is case-insensitive.

Parameters
name:String

the field name to compare to

Returns:boolean

whether this field name is the same as the given string

isSameNameback to summary
public boolean isSameName(HttpField field)

Returns whether this field has the same name as the given field.

The comparison of field name is case-insensitive via is(String).

Parameters
field:HttpField

the field to compare the name to

Returns:boolean

whether this field has the same name as the given field

nameHashCodeback to summary
private int nameHashCode()
stripParametersback to summary
public static String stripParameters(String value)

Returns the field value, stripped of its parameters.

Parameters
value:String

the field value, possibly with parameters

Returns:String

the field value without parameters

See Also
getValueParameters(String, Map)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
valueParametersback to summary
public static String valueParameters(String value, Map<String, String> parameters)

Deprecated

use getValueParameters(String, Map) instead

Annotations
@Deprecated
org.eclipse.jetty.http back to summary

public Class HttpField.IntValueHttpField

extends HttpField
Class Inheritance

A specialized HttpField whose value is an int.

Field Summary

Modifier and TypeField and Description
private final int
Inherited from org.eclipse.jetty.http.HttpField:
NAME_VALUE_TOKENIZERPARAMETER_TOKENIZER

Constructor Summary

AccessConstructor and Description
public
IntValueHttpField(HttpHeader header, String name, String value, int intValue)

public
public
IntValueHttpField(HttpHeader header, String name, int intValue)

public
IntValueHttpField(HttpHeader header, int value)

public
IntValueHttpField(String header, int value)

Method Summary

Modifier and TypeMethod and Description
public int
public long
Inherited from org.eclipse.jetty.http.HttpField:
containscontainscontainsLastcontainsLastequalsgetHeadergetLowerCaseNamegetNamegetValuegetValueListgetValueParametersgetValueshashCodeisisSameNamestripParameterstoStringvalueParameters

Field Detail

_intback to summary
private final int _int

Constructor Detail

IntValueHttpFieldback to summary
public IntValueHttpField(HttpHeader header, String name, String value, int intValue)
IntValueHttpFieldback to summary
public IntValueHttpField(HttpHeader header, String name, String value)
IntValueHttpFieldback to summary
public IntValueHttpField(HttpHeader header, String name, int intValue)
IntValueHttpFieldback to summary
public IntValueHttpField(HttpHeader header, int value)
IntValueHttpFieldback to summary
public IntValueHttpField(String header, int value)

Method Detail

getIntValueback to summary
public int getIntValue()

Overrides org.eclipse.jetty.http.HttpField.getIntValue.

Returns:int

Doc from org.eclipse.jetty.http.HttpField.getIntValue.

the value of this field as an int

Annotations
@Override
getLongValueback to summary
public long getLongValue()

Overrides org.eclipse.jetty.http.HttpField.getLongValue.

Returns:long

Doc from org.eclipse.jetty.http.HttpField.getLongValue.

the value of this field as an long

Annotations
@Override
org.eclipse.jetty.http back to summary

public Class HttpField.LongValueHttpField

extends HttpField
Class Inheritance

A specialized HttpField whose value is a long.

Field Summary

Modifier and TypeField and Description
private final long
Inherited from org.eclipse.jetty.http.HttpField:
NAME_VALUE_TOKENIZERPARAMETER_TOKENIZER

Constructor Summary

AccessConstructor and Description
public
LongValueHttpField(HttpHeader header, String name, String value, long longValue)

public
public
LongValueHttpField(HttpHeader header, String name, long value)

public
LongValueHttpField(HttpHeader header, long value)

public
LongValueHttpField(String header, long value)

Method Summary

Modifier and TypeMethod and Description
public int
public long
Inherited from org.eclipse.jetty.http.HttpField:
containscontainscontainsLastcontainsLastequalsgetHeadergetLowerCaseNamegetNamegetValuegetValueListgetValueParametersgetValueshashCodeisisSameNamestripParameterstoStringvalueParameters

Field Detail

_longback to summary
private final long _long

Constructor Detail

LongValueHttpFieldback to summary
public LongValueHttpField(HttpHeader header, String name, String value, long longValue)
LongValueHttpFieldback to summary
public LongValueHttpField(HttpHeader header, String name, String value)
LongValueHttpFieldback to summary
public LongValueHttpField(HttpHeader header, String name, long value)
LongValueHttpFieldback to summary
public LongValueHttpField(HttpHeader header, long value)
LongValueHttpFieldback to summary
public LongValueHttpField(String header, long value)

Method Detail

getIntValueback to summary
public int getIntValue()

Overrides org.eclipse.jetty.http.HttpField.getIntValue.

Returns:int

Doc from org.eclipse.jetty.http.HttpField.getIntValue.

the value of this field as an int

Annotations
@Override
getLongValueback to summary
public long getLongValue()

Overrides org.eclipse.jetty.http.HttpField.getLongValue.

Returns:long

Doc from org.eclipse.jetty.http.HttpField.getLongValue.

the value of this field as an long

Annotations
@Override
org.eclipse.jetty.http back to summary

pack-priv Class HttpField.MultiHttpField

extends HttpField
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final List<String>
Inherited from org.eclipse.jetty.http.HttpField:
NAME_VALUE_TOKENIZERPARAMETER_TOKENIZER

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static String
public boolean
contains(String
the string to search for
search
)

Overrides org.eclipse.jetty.http.HttpField.contains.

Returns whether this field value, possibly multi-valued, contains the specified search string, case-insensitively.

public List<String>
getValueList()

Overrides org.eclipse.jetty.http.HttpField.getValueList.

Returns a list of the field values.

Inherited from org.eclipse.jetty.http.HttpField:
containscontainsLastcontainsLastequalsgetHeadergetIntValuegetLongValuegetLowerCaseNamegetNamegetValuegetValueParametersgetValueshashCodeisisSameNamestripParameterstoStringvalueParameters

Field Detail

_listback to summary
private final List<String> _list

Constructor Detail

MultiHttpFieldback to summary
public MultiHttpField(String name, List<String> list)

Method Detail

buildValueback to summary
private static String buildValue(List<String> list)
containsback to summary
public boolean contains(String search)

Overrides org.eclipse.jetty.http.HttpField.contains.

Doc from org.eclipse.jetty.http.HttpField.contains.

Returns whether this field value, possibly multi-valued, contains the specified search string, case-insensitively.

Only values, and not parameters, are compared with the search string.

Parameters
search:String

the string to search for

Returns:boolean

whether this field value, possibly multi-valued, contains the specified search string

Annotations
@Override
getValueListback to summary
public List<String> getValueList()

Overrides org.eclipse.jetty.http.HttpField.getValueList.

Doc from org.eclipse.jetty.http.HttpField.getValueList.

Returns a list of the field values.

If the field value is multi-valued, the encoded field value is split into multiple values using QuotedCSV and the different values returned in a list.

If the field value is single-valued, the value is wrapped into a list.

Returns:List<String>

a list of the field values

Annotations
@Override