public abstract class HttpHeaders
extends java.lang.Object
implements java.lang.Iterable<java.util.Map.Entry<java.lang.String,java.lang.String>>
HttpMessage
.Modifier and Type | Class and Description |
---|---|
static class |
HttpHeaders.Names
Standard HTTP header names.
|
static class |
HttpHeaders.Values
Standard HTTP header values.
|
Modifier and Type | Field and Description |
---|---|
static HttpHeaders |
EMPTY_HEADERS |
Modifier | Constructor and Description |
---|---|
protected |
HttpHeaders() |
Modifier and Type | Method and Description |
---|---|
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 . |
abstract HttpHeaders |
add(java.lang.String name,
java.lang.Iterable<?> values) |
abstract HttpHeaders |
add(java.lang.String name,
java.lang.Object value) |
static void |
addDateHeader(HttpMessage message,
java.lang.CharSequence name,
java.util.Date value)
Adds a new date header with the specified name and value.
|
static void |
addDateHeader(HttpMessage message,
java.lang.String name,
java.util.Date value) |
static void |
addHeader(HttpMessage message,
java.lang.CharSequence name,
java.lang.Object value)
Adds a new header with the specified name and value.
|
static void |
addHeader(HttpMessage message,
java.lang.String name,
java.lang.Object value) |
static void |
addIntHeader(HttpMessage message,
java.lang.CharSequence name,
int value)
Adds a new integer header with the specified name and value.
|
static void |
addIntHeader(HttpMessage message,
java.lang.String name,
int value) |
abstract HttpHeaders |
clear()
Removes all headers from this
HttpMessage . |
static void |
clearHeaders(HttpMessage message)
Removes all headers from the specified message.
|
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 ignoreCaseValue)
Returns
true if a header with the name and value exists. |
abstract boolean |
contains(java.lang.String name) |
boolean |
contains(java.lang.String name,
java.lang.String value,
boolean ignoreCaseValue) |
boolean |
containsValue(java.lang.CharSequence name,
java.lang.CharSequence value,
boolean ignoreCase)
Returns
true if a header with the name and value exists, false otherwise. |
static boolean |
encodeAscii(java.lang.CharSequence seq,
ByteBuf buf) |
abstract 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. |
static boolean |
equalsIgnoreCase(java.lang.CharSequence name1,
java.lang.CharSequence name2)
Returns
true if both CharSequence 's are equals when ignore the case. |
java.lang.String |
get(java.lang.CharSequence name)
Returns the value of a header with the specified name.
|
abstract 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
|
abstract java.util.List<java.lang.String> |
getAll(java.lang.String name) |
static long |
getContentLength(HttpMessage message)
Returns the length of the content.
|
static long |
getContentLength(HttpMessage message,
long defaultValue)
Returns the length of the content.
|
static java.util.Date |
getDate(HttpMessage message)
Returns the value of the
"Date" header. |
static java.util.Date |
getDate(HttpMessage message,
java.util.Date defaultValue)
Returns the value of the
"Date" header. |
static java.util.Date |
getDateHeader(HttpMessage message,
java.lang.CharSequence name)
Returns the date header value with the specified header name.
|
static java.util.Date |
getDateHeader(HttpMessage message,
java.lang.CharSequence name,
java.util.Date defaultValue)
Returns the date header value with the specified header name.
|
static java.util.Date |
getDateHeader(HttpMessage message,
java.lang.String name) |
static java.util.Date |
getDateHeader(HttpMessage message,
java.lang.String name,
java.util.Date defaultValue) |
static java.lang.String |
getHeader(HttpMessage message,
java.lang.CharSequence name)
Returns the header value with the specified header name.
|
static java.lang.String |
getHeader(HttpMessage message,
java.lang.CharSequence name,
java.lang.String defaultValue)
Returns the header value with the specified header name.
|
static java.lang.String |
getHeader(HttpMessage message,
java.lang.String name) |
static java.lang.String |
getHeader(HttpMessage message,
java.lang.String name,
java.lang.String defaultValue) |
static java.lang.String |
getHost(HttpMessage message)
Returns the value of the
"Host" header. |
static java.lang.String |
getHost(HttpMessage message,
java.lang.String defaultValue)
Returns the value of the
"Host" header. |
static int |
getIntHeader(HttpMessage message,
java.lang.CharSequence name)
Returns the integer header value with the specified header name.
|
static int |
getIntHeader(HttpMessage message,
java.lang.CharSequence name,
int defaultValue)
Returns the integer header value with the specified header name.
|
static int |
getIntHeader(HttpMessage message,
java.lang.String name) |
static int |
getIntHeader(HttpMessage message,
java.lang.String name,
int defaultValue) |
static boolean |
is100ContinueExpected(HttpMessage message)
Returns
true if and only if the specified message contains the
"Expect: 100-continue" header. |
static boolean |
isContentLengthSet(HttpMessage m) |
abstract boolean |
isEmpty()
Checks if no header exists.
|
static boolean |
isKeepAlive(HttpMessage message)
Returns
true if and only if the connection can remain open and
thus 'kept alive'. |
static boolean |
isTransferEncodingChunked(HttpMessage message)
Checks to see if the transfer encoding in a specified
HttpMessage is chunked |
abstract java.util.Set<java.lang.String> |
names()
Returns a new
Set that contains the names of all headers in this object. |
static java.lang.CharSequence |
newEntity(java.lang.String name)
Create a new
CharSequence which is optimized for reuse as HttpHeaders name or value. |
static java.lang.CharSequence |
newNameEntity(java.lang.String name)
Create a new
CharSequence which is optimized for reuse as HttpHeaders name. |
static java.lang.CharSequence |
newValueEntity(java.lang.String name)
Create a new
CharSequence which is optimized for reuse as HttpHeaders value. |
HttpHeaders |
remove(java.lang.CharSequence name)
Removes the header with the specified name.
|
abstract HttpHeaders |
remove(java.lang.String name) |
static void |
removeHeader(HttpMessage message,
java.lang.CharSequence name)
Removes the header with the specified name.
|
static void |
removeHeader(HttpMessage message,
java.lang.String name) |
static void |
removeTransferEncodingChunked(HttpMessage m) |
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 . |
abstract HttpHeaders |
set(java.lang.String name,
java.lang.Iterable<?> values) |
abstract HttpHeaders |
set(java.lang.String name,
java.lang.Object value) |
static void |
set100ContinueExpected(HttpMessage message)
Sets the
"Expect: 100-continue" header to the specified message. |
static void |
set100ContinueExpected(HttpMessage message,
boolean set)
Sets or removes the
"Expect: 100-continue" header to / from the
specified message. |
static void |
setContentLength(HttpMessage message,
long length)
Sets the
"Content-Length" header. |
static void |
setDate(HttpMessage message,
java.util.Date value)
Sets the
"Date" header. |
static void |
setDateHeader(HttpMessage message,
java.lang.CharSequence name,
java.util.Date value)
Sets a new date header with the specified name and value.
|
static void |
setDateHeader(HttpMessage message,
java.lang.CharSequence name,
java.lang.Iterable<java.util.Date> values)
Sets a new date header with the specified name and values.
|
static void |
setDateHeader(HttpMessage message,
java.lang.String name,
java.util.Date value) |
static void |
setDateHeader(HttpMessage message,
java.lang.String name,
java.lang.Iterable<java.util.Date> values) |
static void |
setHeader(HttpMessage message,
java.lang.CharSequence name,
java.lang.Iterable<?> values)
Sets a new header with the specified name and values.
|
static void |
setHeader(HttpMessage message,
java.lang.CharSequence name,
java.lang.Object value)
Sets a new header with the specified name and value.
|
static void |
setHeader(HttpMessage message,
java.lang.String name,
java.lang.Iterable<?> values) |
static void |
setHeader(HttpMessage message,
java.lang.String name,
java.lang.Object value) |
static void |
setHost(HttpMessage message,
java.lang.CharSequence value)
Sets the
"Host" header. |
static void |
setHost(HttpMessage message,
java.lang.String value) |
static void |
setIntHeader(HttpMessage message,
java.lang.CharSequence name,
int value)
Sets a new integer header with the specified name and value.
|
static void |
setIntHeader(HttpMessage message,
java.lang.CharSequence name,
java.lang.Iterable<java.lang.Integer> values)
Sets a new integer header with the specified name and values.
|
static void |
setIntHeader(HttpMessage message,
java.lang.String name,
int value) |
static void |
setIntHeader(HttpMessage message,
java.lang.String name,
java.lang.Iterable<java.lang.Integer> values) |
static void |
setKeepAlive(HttpMessage message,
boolean keepAlive)
Sets the value of the
"Connection" header depending on the
protocol version of the specified message. |
static void |
setTransferEncodingChunked(HttpMessage m) |
public static final HttpHeaders EMPTY_HEADERS
public static boolean isKeepAlive(HttpMessage message)
true
if and only if the connection can remain open and
thus 'kept alive'. This methods respects the value of the
"Connection"
header first and then the return value of
HttpVersion.isKeepAliveDefault()
.public static void setKeepAlive(HttpMessage message, boolean keepAlive)
"Connection"
header depending on the
protocol version of the specified message. This getMethod sets or removes
the "Connection"
header depending on what the default keep alive
mode of the message's protocol version is, as specified by
HttpVersion.isKeepAliveDefault()
.
"close"
if keepAlive
is false
."keep-alive"
if keepAlive
is true
.public static java.lang.String getHeader(HttpMessage message, java.lang.String name)
#getHeader(HttpMessage, CharSequence)}
public static java.lang.String getHeader(HttpMessage message, java.lang.CharSequence name)
null
if there is no such headerpublic static java.lang.String getHeader(HttpMessage message, java.lang.String name, java.lang.String defaultValue)
public static java.lang.String getHeader(HttpMessage message, java.lang.CharSequence name, java.lang.String defaultValue)
defaultValue
if there is no such
headerpublic static void setHeader(HttpMessage message, java.lang.String name, java.lang.Object value)
public static void setHeader(HttpMessage message, java.lang.CharSequence name, java.lang.Object value)
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.public static void setHeader(HttpMessage message, java.lang.String name, java.lang.Iterable<?> values)
public static void setHeader(HttpMessage message, java.lang.CharSequence name, java.lang.Iterable<?> values)
removeHeader(message, name); for (Object v: values) { if (v == null) { break; } addHeader(message, name, v); }
public static void addHeader(HttpMessage message, java.lang.String name, java.lang.Object value)
public static void addHeader(HttpMessage message, java.lang.CharSequence name, java.lang.Object value)
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.public static void removeHeader(HttpMessage message, java.lang.String name)
removeHeader(HttpMessage, CharSequence)
public static void removeHeader(HttpMessage message, java.lang.CharSequence name)
public static void clearHeaders(HttpMessage message)
public static int getIntHeader(HttpMessage message, java.lang.String name)
getIntHeader(HttpMessage, CharSequence)
public static int getIntHeader(HttpMessage message, java.lang.CharSequence name)
java.lang.NumberFormatException
- if there is no such header or the header value is not a numberpublic static int getIntHeader(HttpMessage message, java.lang.String name, int defaultValue)
public static int getIntHeader(HttpMessage message, java.lang.CharSequence name, int defaultValue)
defaultValue
if there is no such
header or the header value is not a numberpublic static void setIntHeader(HttpMessage message, java.lang.String name, int value)
public static void setIntHeader(HttpMessage message, java.lang.CharSequence name, int value)
public static void setIntHeader(HttpMessage message, java.lang.String name, java.lang.Iterable<java.lang.Integer> values)
public static void setIntHeader(HttpMessage message, java.lang.CharSequence name, java.lang.Iterable<java.lang.Integer> values)
public static void addIntHeader(HttpMessage message, java.lang.String name, int value)
public static void addIntHeader(HttpMessage message, java.lang.CharSequence name, int value)
public static java.util.Date getDateHeader(HttpMessage message, java.lang.String name) throws java.text.ParseException
java.text.ParseException
getDateHeader(HttpMessage, CharSequence)
public static java.util.Date getDateHeader(HttpMessage message, java.lang.CharSequence name) throws java.text.ParseException
java.text.ParseException
- if there is no such header or the header value is not a formatted datepublic static java.util.Date getDateHeader(HttpMessage message, java.lang.String name, java.util.Date defaultValue)
public static java.util.Date getDateHeader(HttpMessage message, java.lang.CharSequence name, java.util.Date defaultValue)
defaultValue
if there is no such
header or the header value is not a formatted datepublic static void setDateHeader(HttpMessage message, java.lang.String name, java.util.Date value)
public static void setDateHeader(HttpMessage message, java.lang.CharSequence name, java.util.Date value)
public static void setDateHeader(HttpMessage message, java.lang.String name, java.lang.Iterable<java.util.Date> values)
public static void setDateHeader(HttpMessage message, java.lang.CharSequence name, java.lang.Iterable<java.util.Date> values)
public static void addDateHeader(HttpMessage message, java.lang.String name, java.util.Date value)
public static void addDateHeader(HttpMessage message, java.lang.CharSequence name, java.util.Date value)
public static long getContentLength(HttpMessage message)
ByteBufHolder.content()
but from the
"Content-Length"
header, and thus they are independent from each
other.java.lang.NumberFormatException
- if the message does not have the "Content-Length"
header
or its value is not a numberpublic static long getContentLength(HttpMessage message, long defaultValue)
ByteBufHolder.content()
but from the
"Content-Length"
header, and thus they are independent from each
other.defaultValue
if this message does
not have the "Content-Length"
header or its value is not
a numberpublic static void setContentLength(HttpMessage message, long length)
"Content-Length"
header.public static java.lang.String getHost(HttpMessage message)
"Host"
header.public static java.lang.String getHost(HttpMessage message, java.lang.String defaultValue)
"Host"
header. If there is no such
header, the defaultValue
is returned.public static void setHost(HttpMessage message, java.lang.String value)
setHost(HttpMessage, CharSequence)
public static void setHost(HttpMessage message, java.lang.CharSequence value)
"Host"
header.public static java.util.Date getDate(HttpMessage message) throws java.text.ParseException
"Date"
header.java.text.ParseException
- if there is no such header or the header value is not a formatted datepublic static java.util.Date getDate(HttpMessage message, java.util.Date defaultValue)
"Date"
header. If there is no such
header or the header is not a formatted date, the defaultValue
is returned.public static void setDate(HttpMessage message, java.util.Date value)
"Date"
header.public static boolean is100ContinueExpected(HttpMessage message)
true
if and only if the specified message contains the
"Expect: 100-continue"
header.public static void set100ContinueExpected(HttpMessage message)
"Expect: 100-continue"
header to the specified message.
If there is any existing "Expect"
header, they are replaced with
the new one.public static void set100ContinueExpected(HttpMessage message, boolean set)
"Expect: 100-continue"
header to / from the
specified message. If set
is true
,
the "Expect: 100-continue"
header is set and all other previous
"Expect"
headers are removed. Otherwise, all "Expect"
headers are removed completely.public static boolean isTransferEncodingChunked(HttpMessage message)
HttpMessage
is chunkedmessage
- The message to checkpublic static void removeTransferEncodingChunked(HttpMessage m)
public static void setTransferEncodingChunked(HttpMessage m)
public static boolean isContentLengthSet(HttpMessage m)
public static boolean equalsIgnoreCase(java.lang.CharSequence name1, java.lang.CharSequence name2)
true
if both CharSequence
's are equals when ignore the case.
This only supports US_ASCII.public static boolean encodeAscii(java.lang.CharSequence seq, ByteBuf buf)
public static java.lang.CharSequence newEntity(java.lang.String name)
CharSequence
which is optimized for reuse as HttpHeaders
name or value.
So if you have a Header name or value that you want to reuse you should make use of this.public static java.lang.CharSequence newNameEntity(java.lang.String name)
CharSequence
which is optimized for reuse as HttpHeaders
name.
So if you have a Header name that you want to reuse you should make use of this.public static java.lang.CharSequence newValueEntity(java.lang.String name)
CharSequence
which is optimized for reuse as HttpHeaders
value.
So if you have a Header value that you want to reuse you should make use of this.public abstract java.lang.String get(java.lang.String name)
#get(CharSequence)}
public java.lang.String get(java.lang.CharSequence name)
name
- The name of the header to searchnull
if there is no such headerpublic abstract java.util.List<java.lang.String> getAll(java.lang.String name)
#getAll(CharSequence)}
public java.util.List<java.lang.String> getAll(java.lang.CharSequence name)
name
- The name of the headers to searchList
of header values which will be empty if no values
are foundpublic abstract java.util.List<java.util.Map.Entry<java.lang.String,java.lang.String>> entries()
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 Iterable.iterator()
instead, which has much less overhead.public abstract boolean contains(java.lang.String name)
contains(CharSequence)
public boolean contains(java.lang.CharSequence name)
name
- The name of the header to search forpublic abstract boolean isEmpty()
public abstract java.util.Set<java.lang.String> names()
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 Iterable.iterator()
instead, which has much less overhead.public abstract HttpHeaders add(java.lang.String name, java.lang.Object value)
#add(CharSequence, Object)}
public HttpHeaders add(java.lang.CharSequence name, java.lang.Object value)
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.name
- The name of the header being addedvalue
- The value of the header being addedthis
public abstract HttpHeaders add(java.lang.String name, java.lang.Iterable<?> values)
#add(CharSequence, Iterable)}
public HttpHeaders add(java.lang.CharSequence name, java.lang.Iterable<?> values)
for (Object v: values) { if (v == null) { break; } headers.add(name, v); }
name
- The name of the headers being setvalues
- The values of the headers being setthis
public HttpHeaders add(HttpHeaders headers)
headers
.this
public abstract HttpHeaders set(java.lang.String name, java.lang.Object value)
#set(CharSequence, Object)}
public HttpHeaders set(java.lang.CharSequence name, java.lang.Object value)
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.name
- The name of the header being setvalue
- The value of the header being setthis
public abstract HttpHeaders set(java.lang.String name, java.lang.Iterable<?> values)
#set(CharSequence, Iterable)}
public HttpHeaders set(java.lang.CharSequence name, java.lang.Iterable<?> values)
headers.remove(name); for (Object v: values) { if (v == null) { break; } headers.add(name, v); }
name
- The name of the headers being setvalues
- The values of the headers being setthis
public HttpHeaders set(HttpHeaders headers)
headers
.this
public abstract HttpHeaders remove(java.lang.String name)
#remove(CharSequence)}
public HttpHeaders remove(java.lang.CharSequence name)
name
- The name of the header to removethis
public abstract HttpHeaders clear()
HttpMessage
.this
public boolean contains(java.lang.String name, java.lang.String value, boolean ignoreCaseValue)
#contains(CharSequence, CharSequence, boolean)}
public boolean containsValue(java.lang.CharSequence name, java.lang.CharSequence value, boolean ignoreCase)
true
if a header with the name
and value
exists, false
otherwise.
This also handles multiple values that are seperated with a ,
.
If ignoreCase
is true
then a case insensitive compare is done on the value.
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 boolean contains(java.lang.CharSequence name, java.lang.CharSequence value, boolean ignoreCaseValue)
true
if a header with the name and value exists.name
- the headernamevalue
- the valueignoreCaseValue
- true
if case should be ignoredtrue
if it contains it false
otherwiseCopyright © 2008–2018 The Netty Project. All rights reserved.