public class DefaultHttpHeaders extends HttpHeaders
HttpHeaders
.HttpHeaders.Names, HttpHeaders.Values
EMPTY_HEADERS
限定符 | 构造器和说明 |
---|---|
|
DefaultHttpHeaders()
Create a new, empty HTTP headers object.
|
|
DefaultHttpHeaders(boolean validate)
已过时。
Prefer using the
DefaultHttpHeaders() constructor instead,
to always have validation enabled. |
protected |
DefaultHttpHeaders(boolean validateValues,
DefaultHeaders.NameValidator<java.lang.CharSequence> nameValidator)
Create an HTTP headers object with the given name validator.
|
protected |
DefaultHttpHeaders(DefaultHeaders.NameValidator<java.lang.CharSequence> nameValidator,
DefaultHeaders.ValueValidator<java.lang.CharSequence> valueValidator)
Create an HTTP headers object with the given name and value validators.
|
protected |
DefaultHttpHeaders(DefaultHeaders.NameValidator<java.lang.CharSequence> nameValidator,
DefaultHeaders.ValueValidator<java.lang.CharSequence> valueValidator,
int sizeHint)
Create an HTTP headers object with the given name and value validators.
|
protected |
DefaultHttpHeaders(DefaultHeaders<java.lang.CharSequence,java.lang.CharSequence,?> headers) |
限定符和类型 | 方法和说明 |
---|---|
HttpHeaders |
add(java.lang.CharSequence name,
java.lang.Iterable<?> values)
Adds a new header with the specified name and values.
|
HttpHeaders |
add(java.lang.CharSequence name,
java.lang.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(java.lang.String name,
java.lang.Iterable<?> values) |
HttpHeaders |
add(java.lang.String name,
java.lang.Object value) |
HttpHeaders |
addInt(java.lang.CharSequence name,
int value)
Add the
name to value . |
HttpHeaders |
addShort(java.lang.CharSequence name,
short value)
Add the
name to value . |
HttpHeaders |
clear()
Removes all headers from this
HttpMessage . |
boolean |
contains(java.lang.CharSequence name)
Checks to see if there is a header with the specified name
|
boolean |
contains(java.lang.CharSequence name,
java.lang.CharSequence value,
boolean ignoreCase)
Returns
true if a header with the name and value exists, false otherwise. |
boolean |
contains(java.lang.String name) |
boolean |
contains(java.lang.String name,
java.lang.String value,
boolean ignoreCase) |
HttpHeaders |
copy()
Returns a deep copy of the passed in
HttpHeaders . |
java.util.List<java.util.Map.Entry<java.lang.String,java.lang.String>> |
entries()
Returns a new
List that contains all headers in this object. |
boolean |
equals(java.lang.Object o) |
java.lang.String |
get(java.lang.CharSequence name)
Returns the value of a header with the specified name.
|
java.lang.String |
get(java.lang.String name) |
java.util.List<java.lang.String> |
getAll(java.lang.CharSequence name)
Returns the values of headers with the specified name
|
java.util.List<java.lang.String> |
getAll(java.lang.String name) |
java.lang.Integer |
getInt(java.lang.CharSequence name)
Returns the integer value of a header with the specified name.
|
int |
getInt(java.lang.CharSequence name,
int defaultValue)
Returns the integer value of a header with the specified name.
|
java.lang.Short |
getShort(java.lang.CharSequence name)
Returns the short value of a header with the specified name.
|
short |
getShort(java.lang.CharSequence name,
short defaultValue)
Returns the short value of a header with the specified name.
|
java.lang.Long |
getTimeMillis(java.lang.CharSequence name)
Returns the date value of a header with the specified name.
|
long |
getTimeMillis(java.lang.CharSequence name,
long defaultValue)
Returns the date value of a header with the specified name.
|
int |
hashCode() |
boolean |
isEmpty()
Checks if no header exists.
|
java.util.Iterator<java.util.Map.Entry<java.lang.String,java.lang.String>> |
iterator()
已过时。
|
java.util.Iterator<java.util.Map.Entry<java.lang.CharSequence,java.lang.CharSequence>> |
iteratorCharSequence() |
java.util.Set<java.lang.String> |
names()
Returns a new
Set that contains the names of all headers in this object. |
HttpHeaders |
remove(java.lang.CharSequence name)
Removes the header with the specified name.
|
HttpHeaders |
remove(java.lang.String name) |
HttpHeaders |
set(java.lang.CharSequence name,
java.lang.Iterable<?> values)
Sets a header with the specified name and values.
|
HttpHeaders |
set(java.lang.CharSequence name,
java.lang.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(java.lang.String name,
java.lang.Iterable<?> values) |
HttpHeaders |
set(java.lang.String name,
java.lang.Object value) |
HttpHeaders |
setInt(java.lang.CharSequence name,
int value)
Set the
name to value . |
HttpHeaders |
setShort(java.lang.CharSequence name,
short value)
Set the
name to value . |
int |
size()
Returns the number of headers in this object.
|
java.util.Iterator<java.lang.CharSequence> |
valueCharSequenceIterator(java.lang.CharSequence name)
Equivalent to
HttpHeaders.getAll(String) but it is possible that no intermediate list is generated. |
java.util.Iterator<java.lang.String> |
valueStringIterator(java.lang.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
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<java.lang.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<java.lang.CharSequence> nameValidator, DefaultHeaders.ValueValidator<java.lang.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<java.lang.CharSequence> nameValidator, DefaultHeaders.ValueValidator<java.lang.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<java.lang.CharSequence,java.lang.CharSequence,?> headers)
public HttpHeaders add(HttpHeaders headers)
HttpHeaders
headers
.add
在类中 HttpHeaders
this
public HttpHeaders set(HttpHeaders headers)
HttpHeaders
headers
.set
在类中 HttpHeaders
this
public HttpHeaders add(java.lang.String name, java.lang.Object value)
add
在类中 HttpHeaders
HttpHeaders.add(CharSequence, Object)
public HttpHeaders add(java.lang.CharSequence name, java.lang.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
在类中 HttpHeaders
name
- The name of the header being addedvalue
- The value of the header being addedthis
public HttpHeaders add(java.lang.String name, java.lang.Iterable<?> values)
add
在类中 HttpHeaders
HttpHeaders.add(CharSequence, Iterable)
public HttpHeaders add(java.lang.CharSequence name, java.lang.Iterable<?> values)
HttpHeaders
for (Object v: values) { if (v == null) { break; } headers.add(name, v); }
add
在类中 HttpHeaders
name
- The name of the headers being setvalues
- The values of the headers being setthis
public HttpHeaders addInt(java.lang.CharSequence name, int value)
HttpHeaders
name
to value
.addInt
在类中 HttpHeaders
name
- The name to modifyvalue
- The valuethis
public HttpHeaders addShort(java.lang.CharSequence name, short value)
HttpHeaders
name
to value
.addShort
在类中 HttpHeaders
name
- The name to modifyvalue
- The valuethis
public HttpHeaders remove(java.lang.String name)
remove
在类中 HttpHeaders
HttpHeaders.remove(CharSequence)
public HttpHeaders remove(java.lang.CharSequence name)
HttpHeaders
remove
在类中 HttpHeaders
name
- The name of the header to removethis
public HttpHeaders set(java.lang.String name, java.lang.Object value)
set
在类中 HttpHeaders
HttpHeaders.set(CharSequence, Object)
public HttpHeaders set(java.lang.CharSequence name, java.lang.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
在类中 HttpHeaders
name
- The name of the header being setvalue
- The value of the header being setthis
public HttpHeaders set(java.lang.String name, java.lang.Iterable<?> values)
set
在类中 HttpHeaders
HttpHeaders.set(CharSequence, Iterable)
public HttpHeaders set(java.lang.CharSequence name, java.lang.Iterable<?> values)
HttpHeaders
headers.remove(name); for (Object v: values) { if (v == null) { break; } headers.add(name, v); }
set
在类中 HttpHeaders
name
- The name of the headers being setvalues
- The values of the headers being setthis
public HttpHeaders setInt(java.lang.CharSequence name, int value)
HttpHeaders
name
to value
. This will remove all previous values associated with name
.setInt
在类中 HttpHeaders
name
- The name to modifyvalue
- The valuethis
public HttpHeaders setShort(java.lang.CharSequence name, short value)
HttpHeaders
name
to value
. This will remove all previous values associated with name
.setShort
在类中 HttpHeaders
name
- The name to modifyvalue
- The valuethis
public HttpHeaders clear()
HttpHeaders
HttpMessage
.clear
在类中 HttpHeaders
this
public java.lang.String get(java.lang.String name)
get
在类中 HttpHeaders
HttpHeaders.get(CharSequence)
public java.lang.String get(java.lang.CharSequence name)
HttpHeaders
get
在类中 HttpHeaders
name
- The name of the header to searchnull
if there is no such headerHttpHeaders.getAsString(CharSequence)
public java.lang.Integer getInt(java.lang.CharSequence name)
HttpHeaders
getInt
在类中 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(java.lang.CharSequence name, int defaultValue)
HttpHeaders
getInt
在类中 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 java.lang.Short getShort(java.lang.CharSequence name)
HttpHeaders
getShort
在类中 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(java.lang.CharSequence name, short defaultValue)
HttpHeaders
getShort
在类中 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 java.lang.Long getTimeMillis(java.lang.CharSequence name)
HttpHeaders
getTimeMillis
在类中 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(java.lang.CharSequence name, long defaultValue)
HttpHeaders
getTimeMillis
在类中 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 java.util.List<java.lang.String> getAll(java.lang.String name)
getAll
在类中 HttpHeaders
HttpHeaders.getAll(CharSequence)
public java.util.List<java.lang.String> getAll(java.lang.CharSequence name)
HttpHeaders
getAll
在类中 HttpHeaders
name
- The name of the headers to searchList
of header values which will be empty if no values
are foundHttpHeaders.getAllAsString(CharSequence)
public java.util.List<java.util.Map.Entry<java.lang.String,java.lang.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
在类中 HttpHeaders
HttpHeaders.iteratorCharSequence()
@Deprecated public java.util.Iterator<java.util.Map.Entry<java.lang.String,java.lang.String>> iterator()
iterator
在接口中 java.lang.Iterable<java.util.Map.Entry<java.lang.String,java.lang.String>>
iterator
在类中 HttpHeaders
public java.util.Iterator<java.util.Map.Entry<java.lang.CharSequence,java.lang.CharSequence>> iteratorCharSequence()
iteratorCharSequence
在类中 HttpHeaders
public java.util.Iterator<java.lang.String> valueStringIterator(java.lang.CharSequence name)
HttpHeaders
HttpHeaders.getAll(String)
but it is possible that no intermediate list is generated.valueStringIterator
在类中 HttpHeaders
name
- the name of the header to retrieveIterator
of header values corresponding to name
.public java.util.Iterator<java.lang.CharSequence> valueCharSequenceIterator(java.lang.CharSequence name)
HttpHeaders
HttpHeaders.getAll(String)
but it is possible that no intermediate list is generated.valueCharSequenceIterator
在类中 HttpHeaders
name
- the name of the header to retrieveIterator
of header values corresponding to name
.public boolean contains(java.lang.String name)
contains
在类中 HttpHeaders
HttpHeaders.contains(CharSequence)
public boolean contains(java.lang.CharSequence name)
HttpHeaders
contains
在类中 HttpHeaders
name
- The name of the header to search forpublic boolean isEmpty()
HttpHeaders
isEmpty
在类中 HttpHeaders
public int size()
HttpHeaders
size
在类中 HttpHeaders
public boolean contains(java.lang.String name, java.lang.String value, boolean ignoreCase)
public boolean contains(java.lang.CharSequence name, java.lang.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
在类中 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 java.util.Set<java.lang.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
在类中 HttpHeaders
public boolean equals(java.lang.Object o)
equals
在类中 java.lang.Object
public int hashCode()
hashCode
在类中 java.lang.Object
public HttpHeaders copy()
HttpHeaders
HttpHeaders
.copy
在类中 HttpHeaders