public class HttpHeaders extends Object
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 | Method and Description |
|---|---|
static void |
addDateHeader(HttpMessage message,
String name,
Date value)
Adds a new date header with the specified name and value.
|
static void |
addHeader(HttpMessage message,
String name,
Object value)
Adds a new header with the specified name and value.
|
static void |
addIntHeader(HttpMessage message,
String name,
int value)
Adds a new integer header with the specified name and value.
|
static void |
clearHeaders(HttpMessage message)
Removes all headers from the specified message.
|
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 Date |
getDate(HttpMessage message)
Returns the value of the
"Date" header. |
static Date |
getDate(HttpMessage message,
Date defaultValue)
Returns the value of the
"Date" header. |
static Date |
getDateHeader(HttpMessage message,
String name)
Returns the date header value with the specified header name.
|
static Date |
getDateHeader(HttpMessage message,
String name,
Date defaultValue)
Returns the date header value with the specified header name.
|
static String |
getHeader(HttpMessage message,
String name)
Returns the header value with the specified header name.
|
static String |
getHeader(HttpMessage message,
String name,
String defaultValue)
Returns the header value with the specified header name.
|
static String |
getHost(HttpMessage message)
Returns the value of the
"Host" header. |
static String |
getHost(HttpMessage message,
String defaultValue)
Returns the value of the
"Host" header. |
static int |
getIntHeader(HttpMessage message,
String name)
Returns the integer header value with the specified header name.
|
static int |
getIntHeader(HttpMessage message,
String name,
int defaultValue)
Returns the integer header value with the specified header name.
|
static boolean |
is100ContinueExpected(HttpMessage message)
Returns
true if and only if the specified message contains the
"Expect: 100-continue" header. |
static boolean |
isKeepAlive(HttpMessage message)
Returns
true if and only if the connection can remain open and
thus 'kept alive'. |
static void |
removeHeader(HttpMessage message,
String name)
Removes the header with the specified name.
|
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,
Date value)
Sets the
"Date" header. |
static void |
setDateHeader(HttpMessage message,
String name,
Date value)
Sets a new date header with the specified name and value.
|
static void |
setDateHeader(HttpMessage message,
String name,
Iterable<Date> values)
Sets a new date header with the specified name and values.
|
static void |
setHeader(HttpMessage message,
String name,
Iterable<?> values)
Sets a new header with the specified name and values.
|
static void |
setHeader(HttpMessage message,
String name,
Object value)
Sets a new header with the specified name and value.
|
static void |
setHost(HttpMessage message,
String value)
Sets the
"Host" header. |
static void |
setIntHeader(HttpMessage message,
String name,
int value)
Sets a new integer header with the specified name and value.
|
static void |
setIntHeader(HttpMessage message,
String name,
Iterable<Integer> values)
Sets a new integer header with the specified name and values.
|
static void |
setKeepAlive(HttpMessage message,
boolean keepAlive)
Sets the value of the
"Connection" header depending on the
protocol version of the specified message. |
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 method 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 String getHeader(HttpMessage message, String name)
null if there is no such headerpublic static String getHeader(HttpMessage message, String name, String defaultValue)
defaultValue if there is no such
headerpublic static void setHeader(HttpMessage message, String name, 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, String name, Iterable<?> values)
removeHeader(message, name);
for (Object v: values) {
if (v == null) {
break;
}
addHeader(message, name, v);
}
public static void addHeader(HttpMessage message, String name, Object value)
public static void removeHeader(HttpMessage message, String name)
public static void clearHeaders(HttpMessage message)
public static int getIntHeader(HttpMessage message, String name)
NumberFormatException - if there is no such header or the header value is not a numberpublic static int getIntHeader(HttpMessage message, String name, int defaultValue)
defaultValue if there is no such
header or the header value is not a numberpublic static void setIntHeader(HttpMessage message, String name, int value)
public static void setIntHeader(HttpMessage message, String name, Iterable<Integer> values)
public static void addIntHeader(HttpMessage message, String name, int value)
public static Date getDateHeader(HttpMessage message, String name) throws ParseException
ParseException - if there is no such header or the header value is not a formatted datepublic static Date getDateHeader(HttpMessage message, String name, Date defaultValue)
defaultValue if there is no such
header or the header value is not a formatted datepublic static void setDateHeader(HttpMessage message, String name, Date value)
public static void setDateHeader(HttpMessage message, String name, Iterable<Date> values)
public static void addDateHeader(HttpMessage message, String name, Date value)
public static long getContentLength(HttpMessage message)
HttpMessage.getContent() but from the
"Content-Length" header, and thus they are independent from each
other.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)
HttpMessage.getContent() 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 String getHost(HttpMessage message)
"Host" header.public static String getHost(HttpMessage message, String defaultValue)
"Host" header. If there is no such
header, the defaultValue is returned.public static void setHost(HttpMessage message, String value)
"Host" header.public static Date getDate(HttpMessage message) throws ParseException
"Date" header.ParseException - if there is no such header or the header value is not a formatted datepublic static Date getDate(HttpMessage message, 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, 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 the specified value is true,
the "Expect: 100-continue" header is set and all other previous
"Expect" headers are removed. Otherwise, all "Expect"
headers are removed completely.Copyright © 2008-2012 The Netty Project. All Rights Reserved.