Class DefaultHttpHeaders
- Direct Known Subclasses:
CombinedHttpHeaders
HttpHeaders
.-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class io.netty.handler.codec.http.HttpHeaders
HttpHeaders.Names, HttpHeaders.Values
-
Field Summary
FieldsFields inherited from class io.netty.handler.codec.http.HttpHeaders
EMPTY_HEADERS
-
Constructor Summary
ConstructorsModifierConstructorDescriptionCreate a new, empty HTTP headers object.DefaultHttpHeaders
(boolean validate) Deprecated.protected
DefaultHttpHeaders
(boolean validateValues, DefaultHeaders.NameValidator<CharSequence> nameValidator) Create an HTTP headers object with the given name validator.protected
DefaultHttpHeaders
(DefaultHeaders.NameValidator<CharSequence> nameValidator, DefaultHeaders.ValueValidator<CharSequence> valueValidator) Create an HTTP headers object with the given name and value validators.protected
DefaultHttpHeaders
(DefaultHeaders.NameValidator<CharSequence> nameValidator, DefaultHeaders.ValueValidator<CharSequence> valueValidator, int sizeHint) Create an HTTP headers object with the given name and value validators.protected
DefaultHttpHeaders
(DefaultHeaders<CharSequence, CharSequence, ?> headers) -
Method Summary
Modifier and TypeMethodDescriptionadd
(HttpHeaders headers) Adds all header entries of the specifiedheaders
.add
(CharSequence name, Iterable<?> values) Adds a new header with the specified name and values.add
(CharSequence name, Object value) Adds a new header with the specified name and value.addInt
(CharSequence name, int value) Add thename
tovalue
.addShort
(CharSequence name, short value) Add thename
tovalue
.clear()
Removes all headers from thisHttpMessage
.boolean
contains
(CharSequence name) Checks to see if there is a header with the specified nameboolean
contains
(CharSequence name, CharSequence value, boolean ignoreCase) Returnstrue
if a header with thename
andvalue
exists,false
otherwise.boolean
boolean
copy()
Returns a deep copy of the passed inHttpHeaders
.entries()
Returns a newList
that contains all headers in this object.boolean
get
(CharSequence name) Returns the value of a header with the specified name.getAll
(CharSequence name) Returns the values of headers with the specified namegetInt
(CharSequence name) Returns the integer value of a header with the specified name.int
getInt
(CharSequence name, int defaultValue) Returns the integer value of a header with the specified name.getShort
(CharSequence name) Returns the short value of a header with the specified name.short
getShort
(CharSequence name, short defaultValue) Returns the short value of a header with the specified name.getTimeMillis
(CharSequence name) Returns the date value of a header with the specified name.long
getTimeMillis
(CharSequence name, long defaultValue) Returns the date value of a header with the specified name.int
hashCode()
boolean
isEmpty()
Checks if no header exists.iterator()
Deprecated.names()
Returns a newSet
that contains the names of all headers in this object.(package private) static DefaultHeaders.NameValidator
<CharSequence> nameValidator
(boolean validate) remove
(CharSequence name) Removes the header with the specified name.set
(HttpHeaders headers) Cleans the current header entries and copies all header entries of the specifiedheaders
.set
(CharSequence name, Iterable<?> values) Sets a header with the specified name and values.set
(CharSequence name, Object value) Sets a header with the specified name and value.setInt
(CharSequence name, int value) Set thename
tovalue
.setShort
(CharSequence name, short value) Set thename
tovalue
.int
size()
Returns the number of headers in this object.Equivalent toHttpHeaders.getAll(String)
but it is possible that no intermediate list is generated.(package private) static ValueConverter
<CharSequence> Equivalent toHttpHeaders.getAll(String)
but it is possible that no intermediate list is generated.(package private) static DefaultHeaders.ValueValidator
<CharSequence> valueValidator
(boolean validate) Methods inherited from class io.netty.handler.codec.http.HttpHeaders
addDateHeader, addDateHeader, addHeader, addHeader, addIntHeader, addIntHeader, clearHeaders, containsValue, encodeAscii, equalsIgnoreCase, get, getAllAsString, getAsString, getContentLength, getContentLength, getDate, getDate, getDateHeader, getDateHeader, getDateHeader, getDateHeader, getHeader, getHeader, getHeader, getHeader, getHost, getHost, getIntHeader, getIntHeader, getIntHeader, getIntHeader, is100ContinueExpected, isContentLengthSet, isKeepAlive, isTransferEncodingChunked, iteratorAsString, newEntity, removeHeader, removeHeader, removeTransferEncodingChunked, set100ContinueExpected, set100ContinueExpected, setAll, setContentLength, setDate, setDateHeader, setDateHeader, setDateHeader, setDateHeader, setHeader, setHeader, setHeader, setHeader, setHost, setHost, setIntHeader, setIntHeader, setIntHeader, setIntHeader, setKeepAlive, setTransferEncodingChunked, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
headers
-
-
Constructor Details
-
DefaultHttpHeaders
public DefaultHttpHeaders()Create a new, empty HTTP headers object.Header names and values are validated as they are added, to ensure they are compliant with the HTTP protocol.
-
DefaultHttpHeaders
Deprecated.Prefer using theDefaultHttpHeaders()
constructor instead, to always have validation enabled.Warning! Settingvalidate
tofalse
will mean that Netty won't validate invalid input: '&' protect against user-supplied header values that are malicious. This can leave your server implementation vulnerable to CWE-113: Improper Neutralization of CRLF Sequences in HTTP Headers ('HTTP Response Splitting') . When disabling this validation, it is the responsibility of the caller to ensure that the values supplied do not contain a non-url-escaped carriage return (CR) and/or line feed (LF) characters.- Parameters:
validate
- Should Netty validate header values to ensure they aren't malicious.
-
DefaultHttpHeaders
protected DefaultHttpHeaders(boolean validateValues, DefaultHeaders.NameValidator<CharSequence> nameValidator) Create an HTTP headers object with the given name validator.Warning! It is strongly recommended that the name validator implement validation that is at least as strict as
HttpHeaderValidationUtil.validateToken(CharSequence)
. It is also strongly recommended thatvalidateValues
is enabled.Without these validations in place, your code can be susceptible to CWE-113: Improper Neutralization of CRLF Sequences in HTTP Headers ('HTTP Response Splitting') . It is the responsibility of the caller to ensure that the values supplied do not contain a non-url-escaped carriage return (CR) and/or line feed (LF) characters.
- Parameters:
validateValues
- Should Netty validate header values to ensure they aren't malicious.nameValidator
- TheDefaultHeaders.NameValidator
to use, neverinvalid @code
{@code null.
-
DefaultHttpHeaders
protected DefaultHttpHeaders(DefaultHeaders.NameValidator<CharSequence> nameValidator, DefaultHeaders.ValueValidator<CharSequence> valueValidator) Create an HTTP headers object with the given name and value validators.Warning! It is strongly recommended that the name validator implement validation that is at least as strict as
HttpHeaderValidationUtil.validateToken(CharSequence)
. And that the value validator is at least as strict asHttpHeaderValidationUtil.validateValidHeaderValue(CharSequence)
.Without these validations in place, your code can be susceptible to CWE-113: Improper Neutralization of CRLF Sequences in HTTP Headers ('HTTP Response Splitting') . It is the responsibility of the caller to ensure that the values supplied do not contain a non-url-escaped carriage return (CR) and/or line feed (LF) characters.
- Parameters:
nameValidator
- TheDefaultHeaders.NameValidator
to use, nevernull
.valueValidator
- TheDefaultHeaders.ValueValidator
to use, nevernull
.
-
DefaultHttpHeaders
protected DefaultHttpHeaders(DefaultHeaders.NameValidator<CharSequence> nameValidator, DefaultHeaders.ValueValidator<CharSequence> valueValidator, int sizeHint) Create an HTTP headers object with the given name and value validators.Warning! It is strongly recommended that the name validator implement validation that is at least as strict as
HttpHeaderValidationUtil.validateToken(CharSequence)
. And that the value validator is at least as strict asHttpHeaderValidationUtil.validateValidHeaderValue(CharSequence)
.Without these validations in place, your code can be susceptible to CWE-113: Improper Neutralization of CRLF Sequences in HTTP Headers ('HTTP Response Splitting') . It is the responsibility of the caller to ensure that the values supplied do not contain a non-url-escaped carriage return (CR) and/or line feed (LF) characters.
- Parameters:
nameValidator
- TheDefaultHeaders.NameValidator
to use, nevernull
.valueValidator
- TheDefaultHeaders.ValueValidator
to use, nevernull
.sizeHint
- A hint about the anticipated number of entries.
-
DefaultHttpHeaders
-
-
Method Details
-
add
Description copied from class:HttpHeaders
Adds all header entries of the specifiedheaders
.- Overrides:
add
in classHttpHeaders
- Returns:
this
-
set
Description copied from class:HttpHeaders
Cleans the current header entries and copies all header entries of the specifiedheaders
.- Overrides:
set
in classHttpHeaders
- Returns:
this
-
add
- Specified by:
add
in classHttpHeaders
- See Also:
-
add
Description copied from class:HttpHeaders
Adds a new header with the specified name and value. If the specified value is not aString
, it is converted into aString
byObject.toString()
, except in the cases ofDate
andCalendar
, which are formatted to the date format defined in RFC2616.- Overrides:
add
in classHttpHeaders
- Parameters:
name
- The name of the header being addedvalue
- The value of the header being added- Returns:
this
-
add
- Specified by:
add
in classHttpHeaders
- See Also:
-
add
Description copied from class:HttpHeaders
Adds a new header with the specified name and values. This getMethod can be represented approximately as the following code:for (Object v: values) { if (v == null) { break; } headers.add(name, v); }
- Overrides:
add
in classHttpHeaders
- Parameters:
name
- The name of the headers being setvalues
- The values of the headers being set- Returns:
this
-
addInt
Description copied from class:HttpHeaders
Add thename
tovalue
.- Specified by:
addInt
in classHttpHeaders
- Parameters:
name
- The name to modifyvalue
- The value- Returns:
this
-
addShort
Description copied from class:HttpHeaders
Add thename
tovalue
.- Specified by:
addShort
in classHttpHeaders
- Parameters:
name
- The name to modifyvalue
- The value- Returns:
this
-
remove
- Specified by:
remove
in classHttpHeaders
- See Also:
-
remove
Description copied from class:HttpHeaders
Removes the header with the specified name.- Overrides:
remove
in classHttpHeaders
- Parameters:
name
- The name of the header to remove- Returns:
this
-
set
- Specified by:
set
in classHttpHeaders
- See Also:
-
set
Description copied from class:HttpHeaders
Sets a header with the specified name and value. If there is an existing header with the same name, it is removed. If the specified value is not aString
, it is converted into aString
byObject.toString()
, except forDate
andCalendar
, which are formatted to the date format defined in RFC2616.- Overrides:
set
in classHttpHeaders
- Parameters:
name
- The name of the header being setvalue
- The value of the header being set- Returns:
this
-
set
- Specified by:
set
in classHttpHeaders
- See Also:
-
set
Description copied from class:HttpHeaders
Sets a header with the specified name and values. If there is an existing header with the same name, it is removed. This getMethod can be represented approximately as the following code:headers.remove(name); for (Object v: values) { if (v == null) { break; } headers.add(name, v); }
- Overrides:
set
in classHttpHeaders
- Parameters:
name
- The name of the headers being setvalues
- The values of the headers being set- Returns:
this
-
setInt
Description copied from class:HttpHeaders
Set thename
tovalue
. This will remove all previous values associated withname
.- Specified by:
setInt
in classHttpHeaders
- Parameters:
name
- The name to modifyvalue
- The value- Returns:
this
-
setShort
Description copied from class:HttpHeaders
Set thename
tovalue
. This will remove all previous values associated withname
.- Specified by:
setShort
in classHttpHeaders
- Parameters:
name
- The name to modifyvalue
- The value- Returns:
this
-
clear
Description copied from class:HttpHeaders
Removes all headers from thisHttpMessage
.- Specified by:
clear
in classHttpHeaders
- Returns:
this
-
get
- Specified by:
get
in classHttpHeaders
- See Also:
-
get
Description copied from class:HttpHeaders
Returns the value of a header with the specified name. If there are more than one values for the specified name, the first value is returned.- Overrides:
get
in classHttpHeaders
- Parameters:
name
- The name of the header to search- Returns:
- The first header value or
null
if there is no such header - See Also:
-
getInt
Description copied from class:HttpHeaders
Returns the integer value of a header with the specified name. If there are more than one values for the specified name, the first value is returned.- Specified by:
getInt
in classHttpHeaders
- Parameters:
name
- the name of the header to search- Returns:
- the first header value if the header is found and its value is an integer.
null
if there's no such header or its value is not an integer.
-
getInt
Description copied from class:HttpHeaders
Returns the integer value of a header with the specified name. If there are more than one values for the specified name, the first value is returned.- Specified by:
getInt
in classHttpHeaders
- Parameters:
name
- the name of the header to searchdefaultValue
- the default value- Returns:
- the first header value if the header is found and its value is an integer.
defaultValue
if there's no such header or its value is not an integer.
-
getShort
Description copied from class:HttpHeaders
Returns the short value of a header with the specified name. If there are more than one values for the specified name, the first value is returned.- Specified by:
getShort
in classHttpHeaders
- Parameters:
name
- the name of the header to search- Returns:
- the first header value if the header is found and its value is a short.
null
if there's no such header or its value is not a short.
-
getShort
Description copied from class:HttpHeaders
Returns the short value of a header with the specified name. If there are more than one values for the specified name, the first value is returned.- Specified by:
getShort
in classHttpHeaders
- Parameters:
name
- the name of the header to searchdefaultValue
- the default value- Returns:
- the first header value if the header is found and its value is a short.
defaultValue
if there's no such header or its value is not a short.
-
getTimeMillis
Description copied from class:HttpHeaders
Returns the date value of a header with the specified name. If there are more than one values for the specified name, the first value is returned.- Specified by:
getTimeMillis
in classHttpHeaders
- Parameters:
name
- the name of the header to search- Returns:
- the first header value if the header is found and its value is a date.
null
if there's no such header or its value is not a date.
-
getTimeMillis
Description copied from class:HttpHeaders
Returns the date value of a header with the specified name. If there are more than one values for the specified name, the first value is returned.- Specified by:
getTimeMillis
in classHttpHeaders
- Parameters:
name
- the name of the header to searchdefaultValue
- the default value- Returns:
- the first header value if the header is found and its value is a date.
defaultValue
if there's no such header or its value is not a date.
-
getAll
- Specified by:
getAll
in classHttpHeaders
- See Also:
-
getAll
Description copied from class:HttpHeaders
Returns the values of headers with the specified name- Overrides:
getAll
in classHttpHeaders
- Parameters:
name
- The name of the headers to search- Returns:
- A
List
of header values which will be empty if no values are found - See Also:
-
entries
Description copied from class:HttpHeaders
Returns a newList
that contains all headers in this object. Note that modifying the returnedList
will not affect the state of this object. If you intend to enumerate over the header entries only, useHttpHeaders.iterator()
instead, which has much less overhead.- Specified by:
entries
in classHttpHeaders
- See Also:
-
iterator
Deprecated. -
iteratorCharSequence
- Specified by:
iteratorCharSequence
in classHttpHeaders
- Returns:
- Iterator over the name/value header pairs.
-
valueStringIterator
Description copied from class:HttpHeaders
Equivalent toHttpHeaders.getAll(String)
but it is possible that no intermediate list is generated.- Overrides:
valueStringIterator
in classHttpHeaders
- Parameters:
name
- the name of the header to retrieve- Returns:
- an
Iterator
of header values corresponding toname
.
-
valueCharSequenceIterator
Description copied from class:HttpHeaders
Equivalent toHttpHeaders.getAll(String)
but it is possible that no intermediate list is generated.- Overrides:
valueCharSequenceIterator
in classHttpHeaders
- Parameters:
name
- the name of the header to retrieve- Returns:
- an
Iterator
of header values corresponding toname
.
-
contains
- Specified by:
contains
in classHttpHeaders
- See Also:
-
contains
Description copied from class:HttpHeaders
Checks to see if there is a header with the specified name- Overrides:
contains
in classHttpHeaders
- Parameters:
name
- The name of the header to search for- Returns:
- True if at least one header is found
-
isEmpty
public boolean isEmpty()Description copied from class:HttpHeaders
Checks if no header exists.- Specified by:
isEmpty
in classHttpHeaders
-
size
public int size()Description copied from class:HttpHeaders
Returns the number of headers in this object.- Specified by:
size
in classHttpHeaders
-
contains
- Overrides:
contains
in classHttpHeaders
- See Also:
-
contains
Description copied from class:HttpHeaders
Returnstrue
if a header with thename
andvalue
exists,false
otherwise.If
ignoreCase
istrue
then a case insensitive compare is done on the value.- Overrides:
contains
in classHttpHeaders
- Parameters:
name
- the name of the header to findvalue
- the value of the header to findignoreCase
-true
then a case insensitive compare is run to compare values. otherwise a case sensitive compare is run to compare values.
-
names
Description copied from class:HttpHeaders
Returns a newSet
that contains the names of all headers in this object. Note that modifying the returnedSet
will not affect the state of this object. If you intend to enumerate over the header entries only, useHttpHeaders.iterator()
instead, which has much less overhead.- Specified by:
names
in classHttpHeaders
-
equals
-
hashCode
public int hashCode() -
copy
Description copied from class:HttpHeaders
Returns a deep copy of the passed inHttpHeaders
.- Overrides:
copy
in classHttpHeaders
-
valueConverter
-
valueValidator
-
nameValidator
-
DefaultHttpHeaders()
constructor instead, to always have validation enabled.