- java.lang.Object
-
- io.netty5.handler.codec.http.HttpHeaders
-
- io.netty5.handler.codec.http.ReadOnlyHttpHeaders
-
@UnstableApi public final class ReadOnlyHttpHeaders extends HttpHeaders
A variant ofHttpHeaders
which only supports read-only methods.Any array passed to this class may be used directly in the underlying data structures of this class. If these arrays may be modified it is the caller's responsibility to supply this class with a copy of the array.
This may be a good alternative to
DefaultHttpHeaders
if your have a fixed set of headers which will not change.
-
-
Constructor Summary
Constructors Constructor Description ReadOnlyHttpHeaders(boolean validateHeaders, CharSequence... nameValuePairs)
Create a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description HttpHeaders
add(String name, Iterable<?> values)
HttpHeaders
add(String name, Object value)
HttpHeaders
addInt(CharSequence name, int value)
Add thename
tovalue
.HttpHeaders
addShort(CharSequence name, short value)
Add thename
tovalue
.HttpHeaders
clear()
Removes all headers from thisHttpMessage
.boolean
contains(String name)
boolean
contains(String name, String value, boolean ignoreCase)
boolean
containsValue(CharSequence name, CharSequence value, boolean ignoreCase)
Returnstrue
if a header with thename
andvalue
exists,false
otherwise.List<Map.Entry<String,String>>
entries()
Returns a newList
that contains all headers in this object.String
get(String 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.boolean
isEmpty()
Checks if no header exists.Iterator<Map.Entry<String,String>>
iterator()
Iterator<Map.Entry<CharSequence,CharSequence>>
iteratorCharSequence()
Set<String>
names()
Returns a newSet
that contains the names of all headers in this object.HttpHeaders
remove(String name)
HttpHeaders
set(String name, Iterable<?> values)
HttpHeaders
set(String name, Object value)
HttpHeaders
setInt(CharSequence name, int value)
Set thename
tovalue
.HttpHeaders
setShort(CharSequence name, short value)
Set thename
tovalue
.int
size()
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
add, add, add, addDateHeader, addDateHeader, addHeader, addHeader, addIntHeader, addIntHeader, clearHeaders, contains, contains, copy, equalsIgnoreCase, get, get, getAll, 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, remove, removeHeader, removeHeader, removeTransferEncodingChunked, set, set, set, 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, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
ReadOnlyHttpHeaders
public ReadOnlyHttpHeaders(boolean validateHeaders, CharSequence... nameValuePairs)
Create a new instance.- Parameters:
validateHeaders
-true
to validate the contents of each header name.nameValuePairs
- An array of the structure[<name,value>,<name,value>,...]
. A copy will NOT be made of this array. If the contents of this array may be modified externally you are responsible for passing in a copy.
-
-
Method Detail
-
get
public String get(String name)
- Specified by:
get
in classHttpHeaders
- See Also:
HttpHeaders.get(CharSequence)
-
getInt
public Integer getInt(CharSequence name)
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
public int getInt(CharSequence name, int defaultValue)
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
public Short getShort(CharSequence name)
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
public short getShort(CharSequence name, short defaultValue)
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
public Long getTimeMillis(CharSequence name)
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
public long getTimeMillis(CharSequence name, long defaultValue)
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
public List<String> getAll(String name)
- Specified by:
getAll
in classHttpHeaders
- See Also:
HttpHeaders.getAll(CharSequence)
-
entries
public List<Map.Entry<String,String>> 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:
HttpHeaders.iteratorCharSequence()
-
contains
public boolean contains(String name)
- Specified by:
contains
in classHttpHeaders
- See Also:
HttpHeaders.contains(CharSequence)
-
contains
public boolean contains(String name, String value, boolean ignoreCase)
- Overrides:
contains
in classHttpHeaders
- See Also:
HttpHeaders.contains(CharSequence, CharSequence, boolean)
-
containsValue
public boolean containsValue(CharSequence name, CharSequence value, boolean ignoreCase)
Description copied from class:HttpHeaders
Returnstrue
if a header with thename
andvalue
exists,false
otherwise. This also handles multiple values that are separated with a,
.If
ignoreCase
istrue
then a case insensitive compare is done on the value.- Overrides:
containsValue
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.
-
valueStringIterator
public Iterator<String> valueStringIterator(CharSequence name)
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
public Iterator<CharSequence> valueCharSequenceIterator(CharSequence name)
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
.
-
iteratorCharSequence
public Iterator<Map.Entry<CharSequence,CharSequence>> iteratorCharSequence()
- Specified by:
iteratorCharSequence
in classHttpHeaders
- Returns:
- Iterator over the name/value header pairs.
-
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
-
names
public Set<String> 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
-
add
public HttpHeaders add(String name, Object value)
- Specified by:
add
in classHttpHeaders
- See Also:
HttpHeaders.add(CharSequence, Object)
-
add
public HttpHeaders add(String name, Iterable<?> values)
- Specified by:
add
in classHttpHeaders
- See Also:
HttpHeaders.add(CharSequence, Iterable)
-
addInt
public HttpHeaders addInt(CharSequence name, int value)
Description copied from class:HttpHeaders
Add thename
tovalue
.- Specified by:
addInt
in classHttpHeaders
- Parameters:
name
- The name to modifyvalue
- The value- Returns:
this
-
addShort
public HttpHeaders addShort(CharSequence name, short value)
Description copied from class:HttpHeaders
Add thename
tovalue
.- Specified by:
addShort
in classHttpHeaders
- Parameters:
name
- The name to modifyvalue
- The value- Returns:
this
-
set
public HttpHeaders set(String name, Object value)
- Specified by:
set
in classHttpHeaders
- See Also:
HttpHeaders.set(CharSequence, Object)
-
set
public HttpHeaders set(String name, Iterable<?> values)
- Specified by:
set
in classHttpHeaders
- See Also:
HttpHeaders.set(CharSequence, Iterable)
-
setInt
public HttpHeaders setInt(CharSequence name, int value)
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
public HttpHeaders setShort(CharSequence name, short value)
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
-
remove
public HttpHeaders remove(String name)
- Specified by:
remove
in classHttpHeaders
- See Also:
HttpHeaders.remove(CharSequence)
-
clear
public HttpHeaders clear()
Description copied from class:HttpHeaders
Removes all headers from thisHttpMessage
.- Specified by:
clear
in classHttpHeaders
- Returns:
this
-
-