Class HttpField
- Direct Known Subclasses:
HostPortHttpField
,HttpCookieUtils.SetCookieHttpField
,HttpField.IntValueHttpField
,HttpField.LongValueHttpField
,PreEncodedHttpField
,ResponseHttpFields.PersistentHttpField
,StaticTableHttpField
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:
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionstatic final QuotedStringTokenizer
A constantQuotedStringTokenizer
configured for quoting/tokenizing a singleparameter
as defined by RFC9110static final QuotedStringTokenizer
A constantQuotedStringTokenizer
configured for quoting/tokenizingparameters
lists as defined by RFC9110 -
Constructor Summary
ConstructorDescriptionCreates a newHttpField
with the given name string and value string.HttpField
(HttpHeader header, String value) Creates a newHttpField
with the givenHttpHeader
and value string.HttpField
(HttpHeader header, String name, String value) Creates a newHttpField
with the givenHttpHeader
, name string and value string.HttpField
(HttpHeader header, HttpHeaderValue value) Creates a newHttpField
with the givenHttpHeader
and value. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Returns whether this field value, possibly multi-valued, contains the specified search string, case-insensitively.static boolean
Returns whether the given value, possibly multi-valued, contains the specified search string, case-insensitively.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.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.boolean
Get theHttpHeader
of this field, ornull
.int
long
Get the field name in lower-case.getName()
Get the field name.getValue()
Get the field value.Returns a list of the field values.static String
getValueParameters
(String valueParams, Map<String, String> parameters) Returns the field value and its parameters.String[]
int
hashCode()
boolean
Returns whether this field name is the same as the given string.boolean
isSameName
(HttpField field) Returns whether this field has the same name as the given field.static String
stripParameters
(String value) Returns the field value, stripped of its parameters.toString()
static String
valueParameters
(String value, Map<String, String> parameters) Deprecated.withoutValue
(String value) Return aHttpField
without a given value (case-insensitive)Return aHttpField
with a given value (case-insensitive) ensuredwithValues
(String... values) Return aHttpField
with given values (case-insensitive) ensured
-
Field Details
-
PARAMETER_TOKENIZER
A constantQuotedStringTokenizer
configured for quoting/tokenizingparameters
lists as defined by RFC9110 -
NAME_VALUE_TOKENIZER
A constantQuotedStringTokenizer
configured for quoting/tokenizing a singleparameter
as defined by RFC9110
-
-
Constructor Details
-
HttpField
Creates a new
HttpField
with the givenHttpHeader
, 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/orHttpField
subclasses that overridegetValue()
.- Parameters:
header
- theHttpHeader
referencing a well-known HTTP header name; may benull
in case of an unknown or custom HTTP header namename
- the field name; ifnull
, thenHttpHeader.asString()
is usedvalue
- the field value; ifnull
, the empty string will be used
-
HttpField
Creates a new
HttpField
with the givenHttpHeader
and value string.- Parameters:
header
- the non-null
HttpHeader
referencing a well-known HTTP header namevalue
- the field value; ifnull
, the empty string will be used
-
HttpField
Creates a new
HttpField
with the givenHttpHeader
and value.- Parameters:
header
- the non-null
HttpHeader
referencing a well-known HTTP header namevalue
- the field value; ifnull
, the empty string will be used
-
HttpField
Creates a new
HttpField
with the given name string and value string.- Parameters:
name
- the non-null
field namevalue
- the field value; ifnull
, the empty string will be used
-
-
Method Details
-
getValueParameters
Returns the field value and its parameters.
A field value may have parameters, typically separated by
;
, for exampleContent-Type: text/plain; charset=UTF-8 Accept: text/html, text/plain; q=0.5
- Parameters:
valueParams
- the field value, possibly with parametersparameters
- An output map to populate with the parameters, ornull
to strip the parameters- Returns:
- the field value without parameters
- See Also:
-
stripParameters
Returns the field value, stripped of its parameters.
- Parameters:
value
- the field value, possibly with parameters- Returns:
- the field value without parameters
- See Also:
-
valueParameters
Deprecated.usegetValueParameters(String, Map)
instead -
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
- the string to search for- Returns:
- whether this field value, possibly multi-valued, contains the specified search string
-
contains
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
- the value string to search intosearch
- the string to search for- Returns:
- whether the given value, possibly multi-valued, contains the specified search string
-
containsLast
Look for a value as the last value in a possible multivalued field Parameters and specifically quality parameters are not considered.- Parameters:
search
- Values 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.
-
containsLast
Look for the last value in a possible multivalued field Parameters and specifically quality parameters are not considered.- Parameters:
value
- The field value to search in.search
- Values 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.
-
hashCode
public int hashCode() -
equals
-
getHeader
Get theHttpHeader
of this field, ornull
.- Returns:
- the
HttpHeader
of this field, ornull
-
getIntValue
public int getIntValue()- Returns:
- the value of this field as an
int
- Throws:
NumberFormatException
- if the value cannot be parsed as anint
-
getLongValue
public long getLongValue()- Returns:
- the value of this field as an
long
- Throws:
NumberFormatException
- if the value cannot be parsed as anlong
-
getLowerCaseName
Get the field name in lower-case.- Returns:
- the field name in lower-case
-
getName
Get the field name.- Returns:
- the field name
-
getValue
Get the field value.- Returns:
- the field value
-
getValues
- Returns:
- the field values as a
String[]
- See Also:
-
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:
- a list of the field values
-
isSameName
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
- the field to compare the name to- Returns:
- whether this field has the same name as the given field
-
is
Returns whether this field name is the same as the given string.
The comparison of field name is case-insensitive.
- Parameters:
name
- the field name to compare to- Returns:
- whether this field name is the same as the given string
-
withoutValue
Return aHttpField
without a given value (case-insensitive) -
withValue
Return aHttpField
with a given value (case-insensitive) ensured -
withValues
Return aHttpField
with given values (case-insensitive) ensured -
toString
-
getValueParameters(String, Map)
instead