public class DefaultHttpHeaders extends HttpHeaders
HttpHeaders
.HttpHeaders.Names, HttpHeaders.Values
EMPTY_HEADERS
Modifier | Constructor and Description |
---|---|
|
DefaultHttpHeaders()
Create a new, empty HTTP headers object.
|
|
DefaultHttpHeaders(boolean validate)
Deprecated.
Prefer using the
DefaultHttpHeaders() constructor instead,
to always have validation enabled. |
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) |
Modifier and Type | Method and Description |
---|---|
HttpHeaders |
add(CharSequence name,
Iterable<?> values)
Adds a new header with the specified name and values.
|
HttpHeaders |
add(CharSequence name,
Object value)
Adds a new header with the specified name and value.
|
HttpHeaders |
add(HttpHeaders headers)
Adds all header entries of the specified
headers . |
HttpHeaders |
add(String name,
Iterable<?> values) |
HttpHeaders |
add(String name,
Object value) |
HttpHeaders |
addInt(CharSequence name,
int value)
Add the
name to value . |
HttpHeaders |
addShort(CharSequence name,
short value)
Add the
name to value . |
HttpHeaders |
clear()
Removes all headers from this
HttpMessage . |
boolean |
contains(CharSequence name)
Checks to see if there is a header with the specified name
|
boolean |
contains(CharSequence name,
CharSequence value,
boolean ignoreCase)
Returns
true if a header with the name and value exists, false otherwise. |
boolean |
contains(String name) |
boolean |
contains(String name,
String value,
boolean ignoreCase) |
HttpHeaders |
copy()
Returns a deep copy of the passed in
HttpHeaders . |
List<Map.Entry<String,String>> |
entries()
Returns a new
List that contains all headers in this object. |
boolean |
equals(Object o) |
String |
get(CharSequence name)
Returns the value of a header with the specified name.
|
String |
get(String name) |
List<String> |
getAll(CharSequence name)
Returns the values of headers with the specified name
|
List<String> |
getAll(String name) |
Integer |
getInt(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.
|
Short |
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.
|
Long |
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<Map.Entry<String,String>> |
iterator()
Deprecated.
|
Iterator<Map.Entry<CharSequence,CharSequence>> |
iteratorCharSequence() |
Set<String> |
names()
Returns a new
Set that contains the names of all headers in this object. |
HttpHeaders |
remove(CharSequence name)
Removes the header with the specified name.
|
HttpHeaders |
remove(String name) |
HttpHeaders |
set(CharSequence name,
Iterable<?> values)
Sets a header with the specified name and values.
|
HttpHeaders |
set(CharSequence name,
Object value)
Sets a header with the specified name and value.
|
HttpHeaders |
set(HttpHeaders headers)
Cleans the current header entries and copies all header entries of the specified
headers . |
HttpHeaders |
set(String name,
Iterable<?> values) |
HttpHeaders |
set(String name,
Object value) |
HttpHeaders |
setInt(CharSequence name,
int value)
Set the
name to value . |
HttpHeaders |
setShort(CharSequence name,
short value)
Set the
name to value . |
int |
size()
Returns the number of headers in this object.
|
Headers<CharSequence,CharSequence,?> |
unwrap() |
Iterator<CharSequence> |
valueCharSequenceIterator(CharSequence name)
Equivalent to
HttpHeaders.getAll(String) but it is possible that no intermediate list is generated. |
Iterator<String> |
valueStringIterator(CharSequence name)
Equivalent to
HttpHeaders.getAll(String) but it is possible that no intermediate list is generated. |
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
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
forEach, spliterator
public DefaultHttpHeaders()
Header names and values are validated as they are added, to ensure they are compliant with the HTTP protocol.
@Deprecated public DefaultHttpHeaders(boolean validate)
DefaultHttpHeaders()
constructor instead,
to always have validation enabled.validate
to false
will mean that Netty won't
validate & 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.validate
- Should Netty validate header values to ensure they aren't malicious.protected DefaultHttpHeaders(boolean validateValues, DefaultHeaders.NameValidator<CharSequence> nameValidator)
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 that validateValues
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.
validateValues
- Should Netty validate header values to ensure they aren't malicious.nameValidator
- The DefaultHeaders.NameValidator
to use, never {@code null.protected DefaultHttpHeaders(DefaultHeaders.NameValidator<CharSequence> nameValidator, DefaultHeaders.ValueValidator<CharSequence> valueValidator)
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 as
HttpHeaderValidationUtil.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.
nameValidator
- The DefaultHeaders.NameValidator
to use, never null
.valueValidator
- The DefaultHeaders.ValueValidator
to use, never null
.protected DefaultHttpHeaders(DefaultHeaders.NameValidator<CharSequence> nameValidator, DefaultHeaders.ValueValidator<CharSequence> valueValidator, int sizeHint)
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 as
HttpHeaderValidationUtil.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.
nameValidator
- The DefaultHeaders.NameValidator
to use, never null
.valueValidator
- The DefaultHeaders.ValueValidator
to use, never null
.sizeHint
- A hint about the anticipated number of entries.protected DefaultHttpHeaders(DefaultHeaders<CharSequence,CharSequence,?> headers)
public Headers<CharSequence,CharSequence,?> unwrap()
public HttpHeaders add(HttpHeaders headers)
HttpHeaders
headers
.add
in class HttpHeaders
this
public HttpHeaders set(HttpHeaders headers)
HttpHeaders
headers
.set
in class HttpHeaders
this
public HttpHeaders add(String name, Object value)
add
in class HttpHeaders
HttpHeaders.add(CharSequence, Object)
public HttpHeaders add(CharSequence name, Object value)
HttpHeaders
String
, it is converted
into a String
by Object.toString()
, except in the cases
of Date
and Calendar
, which are formatted to the date
format defined in RFC2616.add
in class HttpHeaders
name
- The name of the header being addedvalue
- The value of the header being addedthis
public HttpHeaders add(String name, Iterable<?> values)
add
in class HttpHeaders
HttpHeaders.add(CharSequence, Iterable)
public HttpHeaders add(CharSequence name, Iterable<?> values)
HttpHeaders
for (Object v: values) { if (v == null) { break; } headers.add(name, v); }
add
in class HttpHeaders
name
- The name of the headers being setvalues
- The values of the headers being setthis
public HttpHeaders addInt(CharSequence name, int value)
HttpHeaders
name
to value
.addInt
in class HttpHeaders
name
- The name to modifyvalue
- The valuethis
public HttpHeaders addShort(CharSequence name, short value)
HttpHeaders
name
to value
.addShort
in class HttpHeaders
name
- The name to modifyvalue
- The valuethis
public HttpHeaders remove(String name)
remove
in class HttpHeaders
HttpHeaders.remove(CharSequence)
public HttpHeaders remove(CharSequence name)
HttpHeaders
remove
in class HttpHeaders
name
- The name of the header to removethis
public HttpHeaders set(String name, Object value)
set
in class HttpHeaders
HttpHeaders.set(CharSequence, Object)
public HttpHeaders set(CharSequence name, Object value)
HttpHeaders
String
, it is converted into a
String
by Object.toString()
, except for Date
and Calendar
, which are formatted to the date format defined in
RFC2616.set
in class HttpHeaders
name
- The name of the header being setvalue
- The value of the header being setthis
public HttpHeaders set(String name, Iterable<?> values)
set
in class HttpHeaders
HttpHeaders.set(CharSequence, Iterable)
public HttpHeaders set(CharSequence name, Iterable<?> values)
HttpHeaders
headers.remove(name); for (Object v: values) { if (v == null) { break; } headers.add(name, v); }
set
in class HttpHeaders
name
- The name of the headers being setvalues
- The values of the headers being setthis
public HttpHeaders setInt(CharSequence name, int value)
HttpHeaders
name
to value
. This will remove all previous values associated with name
.setInt
in class HttpHeaders
name
- The name to modifyvalue
- The valuethis
public HttpHeaders setShort(CharSequence name, short value)
HttpHeaders
name
to value
. This will remove all previous values associated with name
.setShort
in class HttpHeaders
name
- The name to modifyvalue
- The valuethis
public HttpHeaders clear()
HttpHeaders
HttpMessage
.clear
in class HttpHeaders
this
public String get(String name)
get
in class HttpHeaders
HttpHeaders.get(CharSequence)
public String get(CharSequence name)
HttpHeaders
get
in class HttpHeaders
name
- The name of the header to searchnull
if there is no such headerHttpHeaders.getAsString(CharSequence)
public Integer getInt(CharSequence name)
HttpHeaders
getInt
in class HttpHeaders
name
- the name of the header to searchnull
if there's no
such header or its value is not an integer.public int getInt(CharSequence name, int defaultValue)
HttpHeaders
getInt
in class HttpHeaders
name
- the name of the header to searchdefaultValue
- the default valuedefaultValue
if
there's no such header or its value is not an integer.public Short getShort(CharSequence name)
HttpHeaders
getShort
in class HttpHeaders
name
- the name of the header to searchnull
if there's no
such header or its value is not a short.public short getShort(CharSequence name, short defaultValue)
HttpHeaders
getShort
in class HttpHeaders
name
- the name of the header to searchdefaultValue
- the default valuedefaultValue
if
there's no such header or its value is not a short.public Long getTimeMillis(CharSequence name)
HttpHeaders
getTimeMillis
in class HttpHeaders
name
- the name of the header to searchnull
if there's no
such header or its value is not a date.public long getTimeMillis(CharSequence name, long defaultValue)
HttpHeaders
getTimeMillis
in class HttpHeaders
name
- the name of the header to searchdefaultValue
- the default valuedefaultValue
if
there's no such header or its value is not a date.public List<String> getAll(String name)
getAll
in class HttpHeaders
HttpHeaders.getAll(CharSequence)
public List<String> getAll(CharSequence name)
HttpHeaders
getAll
in class HttpHeaders
name
- The name of the headers to searchList
of header values which will be empty if no values
are foundHttpHeaders.getAllAsString(CharSequence)
public List<Map.Entry<String,String>> entries()
HttpHeaders
List
that contains all headers in this object. Note that modifying the
returned List
will not affect the state of this object. If you intend to enumerate over the header
entries only, use HttpHeaders.iterator()
instead, which has much less overhead.entries
in class HttpHeaders
HttpHeaders.iteratorCharSequence()
@Deprecated public Iterator<Map.Entry<String,String>> iterator()
public Iterator<Map.Entry<CharSequence,CharSequence>> iteratorCharSequence()
iteratorCharSequence
in class HttpHeaders
public Iterator<String> valueStringIterator(CharSequence name)
HttpHeaders
HttpHeaders.getAll(String)
but it is possible that no intermediate list is generated.valueStringIterator
in class HttpHeaders
name
- the name of the header to retrieveIterator
of header values corresponding to name
.public Iterator<CharSequence> valueCharSequenceIterator(CharSequence name)
HttpHeaders
HttpHeaders.getAll(String)
but it is possible that no intermediate list is generated.valueCharSequenceIterator
in class HttpHeaders
name
- the name of the header to retrieveIterator
of header values corresponding to name
.public boolean contains(String name)
contains
in class HttpHeaders
HttpHeaders.contains(CharSequence)
public boolean contains(CharSequence name)
HttpHeaders
contains
in class HttpHeaders
name
- The name of the header to search forpublic boolean isEmpty()
HttpHeaders
isEmpty
in class HttpHeaders
public int size()
HttpHeaders
size
in class HttpHeaders
public boolean contains(String name, String value, boolean ignoreCase)
contains
in class HttpHeaders
HttpHeaders.contains(CharSequence, CharSequence, boolean)
public boolean contains(CharSequence name, CharSequence value, boolean ignoreCase)
HttpHeaders
true
if a header with the name
and value
exists, false
otherwise.
If ignoreCase
is true
then a case insensitive compare is done on the value.
contains
in class HttpHeaders
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.public Set<String> names()
HttpHeaders
Set
that contains the names of all headers in this object. Note that modifying the
returned Set
will not affect the state of this object. If you intend to enumerate over the header
entries only, use HttpHeaders.iterator()
instead, which has much less overhead.names
in class HttpHeaders
public HttpHeaders copy()
HttpHeaders
HttpHeaders
.copy
in class HttpHeaders
Copyright © 2008–2024 The Netty Project. All rights reserved.