- java.lang.Object
-
- io.netty5.handler.codec.http.HttpHeaders
-
- io.netty5.handler.codec.http.DefaultHttpHeaders
-
- Direct Known Subclasses:
CombinedHttpHeaders
public class DefaultHttpHeaders extends HttpHeaders
Default implementation ofHttpHeaders.
-
-
Constructor Summary
Constructors Modifier Constructor Description DefaultHttpHeaders()DefaultHttpHeaders(boolean validate)Warning!protectedDefaultHttpHeaders(boolean validate, DefaultHeaders.NameValidator<CharSequence> nameValidator)protectedDefaultHttpHeaders(DefaultHeaders<CharSequence,CharSequence,?> headers)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description HttpHeadersadd(HttpHeaders headers)Adds all header entries of the specifiedheaders.HttpHeadersadd(CharSequence name, Iterable<?> values)Adds a new header with the specified name and values.HttpHeadersadd(CharSequence name, Object value)Adds a new header with the specified name and value.HttpHeadersadd(String name, Iterable<?> values)HttpHeadersadd(String name, Object value)HttpHeadersaddInt(CharSequence name, int value)Add thenametovalue.HttpHeadersaddShort(CharSequence name, short value)Add thenametovalue.HttpHeadersclear()Removes all headers from thisHttpMessage.booleancontains(CharSequence name)Checks to see if there is a header with the specified namebooleancontains(CharSequence name, CharSequence value, boolean ignoreCase)Returnstrueif a header with thenameandvalueexists,falseotherwise.booleancontains(String name)booleancontains(String name, String value, boolean ignoreCase)HttpHeaderscopy()Returns a deep copy of the passed inHttpHeaders.List<Map.Entry<String,String>>entries()Returns a newListthat contains all headers in this object.booleanequals(Object o)Stringget(CharSequence name)Returns the value of a header with the specified name.Stringget(String name)List<String>getAll(CharSequence name)Returns the values of headers with the specified nameList<String>getAll(String name)IntegergetInt(CharSequence name)Returns the integer value of a header with the specified name.intgetInt(CharSequence name, int defaultValue)Returns the integer value of a header with the specified name.ShortgetShort(CharSequence name)Returns the short value of a header with the specified name.shortgetShort(CharSequence name, short defaultValue)Returns the short value of a header with the specified name.LonggetTimeMillis(CharSequence name)Returns the date value of a header with the specified name.longgetTimeMillis(CharSequence name, long defaultValue)Returns the date value of a header with the specified name.inthashCode()booleanisEmpty()Checks if no header exists.Iterator<Map.Entry<String,String>>iterator()Deprecated.Iterator<Map.Entry<CharSequence,CharSequence>>iteratorCharSequence()Set<String>names()Returns a newSetthat contains the names of all headers in this object.HttpHeadersremove(CharSequence name)Removes the header with the specified name.HttpHeadersremove(String name)HttpHeadersset(HttpHeaders headers)Cleans the current header entries and copies all header entries of the specifiedheaders.HttpHeadersset(CharSequence name, Iterable<?> values)Sets a header with the specified name and values.HttpHeadersset(CharSequence name, Object value)Sets a header with the specified name and value.HttpHeadersset(String name, Iterable<?> values)HttpHeadersset(String name, Object value)HttpHeaderssetInt(CharSequence name, int value)Set thenametovalue.HttpHeaderssetShort(CharSequence name, short value)Set thenametovalue.intsize()Returns the number of headers in this object.Iterator<CharSequence>valueCharSequenceIterator(CharSequence name)Equivalent toHttpHeaders.getAll(String)but it is possible that no intermediate list is generated.Iterator<String>valueStringIterator(CharSequence name)Equivalent toHttpHeaders.getAll(String)but it is possible that no intermediate list is generated.-
Methods inherited from class io.netty5.handler.codec.http.HttpHeaders
addDateHeader, addDateHeader, addHeader, addHeader, addIntHeader, addIntHeader, clearHeaders, containsValue, 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
-
-
-
-
Constructor Detail
-
DefaultHttpHeaders
public DefaultHttpHeaders()
-
DefaultHttpHeaders
public DefaultHttpHeaders(boolean validate)
Warning! Settingvalidatetofalsewill 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.- Parameters:
validate- Should Netty validate Header values to ensure they aren't malicious.
-
DefaultHttpHeaders
protected DefaultHttpHeaders(boolean validate, DefaultHeaders.NameValidator<CharSequence> nameValidator)
-
DefaultHttpHeaders
protected DefaultHttpHeaders(DefaultHeaders<CharSequence,CharSequence,?> headers)
-
-
Method Detail
-
add
public HttpHeaders add(HttpHeaders headers)
Description copied from class:HttpHeadersAdds all header entries of the specifiedheaders.- Overrides:
addin classHttpHeaders- Returns:
this
-
set
public HttpHeaders set(HttpHeaders headers)
Description copied from class:HttpHeadersCleans the current header entries and copies all header entries of the specifiedheaders.- Overrides:
setin classHttpHeaders- Returns:
this
-
add
public HttpHeaders add(String name, Object value)
- Specified by:
addin classHttpHeaders- See Also:
HttpHeaders.add(CharSequence, Object)
-
add
public HttpHeaders add(CharSequence name, Object value)
Description copied from class:HttpHeadersAdds a new header with the specified name and value. If the specified value is not aString, it is converted into aStringbyObject.toString(), except in the cases ofDateandCalendar, which are formatted to the date format defined in RFC2616.- Overrides:
addin classHttpHeaders- Parameters:
name- The name of the header being addedvalue- The value of the header being added- Returns:
this
-
add
public HttpHeaders add(String name, Iterable<?> values)
- Specified by:
addin classHttpHeaders- See Also:
HttpHeaders.add(CharSequence, Iterable)
-
add
public HttpHeaders add(CharSequence name, Iterable<?> values)
Description copied from class:HttpHeadersAdds 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:
addin classHttpHeaders- Parameters:
name- The name of the headers being setvalues- The values of the headers being set- Returns:
this
-
addInt
public HttpHeaders addInt(CharSequence name, int value)
Description copied from class:HttpHeadersAdd thenametovalue.- Specified by:
addIntin classHttpHeaders- Parameters:
name- The name to modifyvalue- The value- Returns:
this
-
addShort
public HttpHeaders addShort(CharSequence name, short value)
Description copied from class:HttpHeadersAdd thenametovalue.- Specified by:
addShortin classHttpHeaders- Parameters:
name- The name to modifyvalue- The value- Returns:
this
-
remove
public HttpHeaders remove(String name)
- Specified by:
removein classHttpHeaders- See Also:
HttpHeaders.remove(CharSequence)
-
remove
public HttpHeaders remove(CharSequence name)
Description copied from class:HttpHeadersRemoves the header with the specified name.- Overrides:
removein classHttpHeaders- Parameters:
name- The name of the header to remove- Returns:
this
-
set
public HttpHeaders set(String name, Object value)
- Specified by:
setin classHttpHeaders- See Also:
HttpHeaders.set(CharSequence, Object)
-
set
public HttpHeaders set(CharSequence name, Object value)
Description copied from class:HttpHeadersSets 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 aStringbyObject.toString(), except forDateandCalendar, which are formatted to the date format defined in RFC2616.- Overrides:
setin classHttpHeaders- Parameters:
name- The name of the header being setvalue- The value of the header being set- Returns:
this
-
set
public HttpHeaders set(String name, Iterable<?> values)
- Specified by:
setin classHttpHeaders- See Also:
HttpHeaders.set(CharSequence, Iterable)
-
set
public HttpHeaders set(CharSequence name, Iterable<?> values)
Description copied from class:HttpHeadersSets 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:
setin classHttpHeaders- Parameters:
name- The name of the headers being setvalues- The values of the headers being set- Returns:
this
-
setInt
public HttpHeaders setInt(CharSequence name, int value)
Description copied from class:HttpHeadersSet thenametovalue. This will remove all previous values associated withname.- Specified by:
setIntin classHttpHeaders- Parameters:
name- The name to modifyvalue- The value- Returns:
this
-
setShort
public HttpHeaders setShort(CharSequence name, short value)
Description copied from class:HttpHeadersSet thenametovalue. This will remove all previous values associated withname.- Specified by:
setShortin classHttpHeaders- Parameters:
name- The name to modifyvalue- The value- Returns:
this
-
clear
public HttpHeaders clear()
Description copied from class:HttpHeadersRemoves all headers from thisHttpMessage.- Specified by:
clearin classHttpHeaders- Returns:
this
-
get
public String get(String name)
- Specified by:
getin classHttpHeaders- See Also:
HttpHeaders.get(CharSequence)
-
get
public String get(CharSequence name)
Description copied from class:HttpHeadersReturns 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:
getin classHttpHeaders- Parameters:
name- The name of the header to search- Returns:
- The first header value or
nullif there is no such header - See Also:
HttpHeaders.getAsString(CharSequence)
-
getInt
public Integer getInt(CharSequence name)
Description copied from class:HttpHeadersReturns 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:
getIntin 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.
nullif there's no such header or its value is not an integer.
-
getInt
public int getInt(CharSequence name, int defaultValue)
Description copied from class:HttpHeadersReturns 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:
getIntin 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.
defaultValueif there's no such header or its value is not an integer.
-
getShort
public Short getShort(CharSequence name)
Description copied from class:HttpHeadersReturns 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:
getShortin 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.
nullif there's no such header or its value is not a short.
-
getShort
public short getShort(CharSequence name, short defaultValue)
Description copied from class:HttpHeadersReturns 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:
getShortin 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.
defaultValueif there's no such header or its value is not a short.
-
getTimeMillis
public Long getTimeMillis(CharSequence name)
Description copied from class:HttpHeadersReturns 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:
getTimeMillisin 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.
nullif there's no such header or its value is not a date.
-
getTimeMillis
public long getTimeMillis(CharSequence name, long defaultValue)
Description copied from class:HttpHeadersReturns 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:
getTimeMillisin 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.
defaultValueif there's no such header or its value is not a date.
-
getAll
public List<String> getAll(String name)
- Specified by:
getAllin classHttpHeaders- See Also:
HttpHeaders.getAll(CharSequence)
-
getAll
public List<String> getAll(CharSequence name)
Description copied from class:HttpHeadersReturns the values of headers with the specified name- Overrides:
getAllin classHttpHeaders- Parameters:
name- The name of the headers to search- Returns:
- A
Listof header values which will be empty if no values are found - See Also:
HttpHeaders.getAllAsString(CharSequence)
-
entries
public List<Map.Entry<String,String>> entries()
Description copied from class:HttpHeadersReturns a newListthat contains all headers in this object. Note that modifying the returnedListwill 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:
entriesin classHttpHeaders- See Also:
HttpHeaders.iteratorCharSequence()
-
iterator
@Deprecated public Iterator<Map.Entry<String,String>> iterator()
Deprecated.
-
iteratorCharSequence
public Iterator<Map.Entry<CharSequence,CharSequence>> iteratorCharSequence()
- Specified by:
iteratorCharSequencein classHttpHeaders- Returns:
- Iterator over the name/value header pairs.
-
valueStringIterator
public Iterator<String> valueStringIterator(CharSequence name)
Description copied from class:HttpHeadersEquivalent toHttpHeaders.getAll(String)but it is possible that no intermediate list is generated.- Overrides:
valueStringIteratorin classHttpHeaders- Parameters:
name- the name of the header to retrieve- Returns:
- an
Iteratorof header values corresponding toname.
-
valueCharSequenceIterator
public Iterator<CharSequence> valueCharSequenceIterator(CharSequence name)
Description copied from class:HttpHeadersEquivalent toHttpHeaders.getAll(String)but it is possible that no intermediate list is generated.- Overrides:
valueCharSequenceIteratorin classHttpHeaders- Parameters:
name- the name of the header to retrieve- Returns:
- an
Iteratorof header values corresponding toname.
-
contains
public boolean contains(String name)
- Specified by:
containsin classHttpHeaders- See Also:
HttpHeaders.contains(CharSequence)
-
contains
public boolean contains(CharSequence name)
Description copied from class:HttpHeadersChecks to see if there is a header with the specified name- Overrides:
containsin 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:HttpHeadersChecks if no header exists.- Specified by:
isEmptyin classHttpHeaders
-
size
public int size()
Description copied from class:HttpHeadersReturns the number of headers in this object.- Specified by:
sizein classHttpHeaders
-
contains
public boolean contains(String name, String value, boolean ignoreCase)
- Overrides:
containsin classHttpHeaders- See Also:
HttpHeaders.contains(CharSequence, CharSequence, boolean)
-
contains
public boolean contains(CharSequence name, CharSequence value, boolean ignoreCase)
Description copied from class:HttpHeadersReturnstrueif a header with thenameandvalueexists,falseotherwise.If
ignoreCaseistruethen a case insensitive compare is done on the value.- Overrides:
containsin classHttpHeaders- Parameters:
name- the name of the header to findvalue- the value of the header to findignoreCase-truethen a case insensitive compare is run to compare values. otherwise a case sensitive compare is run to compare values.
-
names
public Set<String> names()
Description copied from class:HttpHeadersReturns a newSetthat contains the names of all headers in this object. Note that modifying the returnedSetwill 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:
namesin classHttpHeaders
-
copy
public HttpHeaders copy()
Description copied from class:HttpHeadersReturns a deep copy of the passed inHttpHeaders.- Overrides:
copyin classHttpHeaders
-
-