Class HttpHeaders
java.lang.Object
org.jboss.netty.handler.codec.http.HttpHeaders
- Direct Known Subclasses:
DefaultHttpHeaders
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classStandard HTTP header names.static final classStandard HTTP header values. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract HttpHeadersAdds a new header with the specified name and values.abstract HttpHeadersAdds a new header with the specified name and value.add(HttpHeaders headers) Adds all header entries of the specifiedheaders.static voidaddDateHeader(HttpMessage message, String name, Date value) Adds a new date header with the specified name and value.static voidaddHeader(HttpMessage message, String name, Object value) Adds a new header with the specified name and value.static voidaddIntHeader(HttpMessage message, String name, int value) Adds a new integer header with the specified name and value.abstract HttpHeadersclear()Removes all headers from thisHttpMessage.static voidclearHeaders(HttpMessage message) Removes all headers from the specified message.abstract booleanChecks to see if there is a header with the specified namebooleanReturnstrueif a header with the name and value exists.entries()Returns a newListthat contains all headers in this object.abstract StringReturns the value of a header with the specified name.Returns the values of headers with the specified namestatic longgetContentLength(HttpMessage message) Returns the length of the content.static longgetContentLength(HttpMessage message, long defaultValue) Returns the length of the content.static DategetDate(HttpMessage message) Returns the value of the"Date"header.static DategetDate(HttpMessage message, Date defaultValue) Returns the value of the"Date"header.static DategetDateHeader(HttpMessage message, String name) Returns the date header value with the specified header name.static DategetDateHeader(HttpMessage message, String name, Date defaultValue) Returns the date header value with the specified header name.static StringgetHeader(HttpMessage message, String name) Returns the header value with the specified header name.static StringgetHeader(HttpMessage message, String name, String defaultValue) Returns the header value with the specified header name.static StringgetHost(HttpMessage message) Returns the value of the"Host"header.static StringgetHost(HttpMessage message, String defaultValue) Returns the value of the"Host"header.static intgetIntHeader(HttpMessage message, String name) Returns the integer header value with the specified header name.static intgetIntHeader(HttpMessage message, String name, int defaultValue) Returns the integer header value with the specified header name.private static intgetWebSocketContentLength(HttpMessage message) Returns the content length of the specified web socket message.static booleanis100ContinueExpected(HttpMessage message) Returnstrueif and only if the specified message contains the"Expect: 100-continue"header.static booleanabstract booleanisEmpty()Checks if no header exists.static booleanisKeepAlive(HttpMessage message) Returnstrueif and only if the connection can remain open and thus 'kept alive'.static booleanisTransferEncodingChunked(HttpMessage message) Checks to see if the transfer encoding in a specifiedHttpMessageis chunkednames()Returns a newSetthat contains the names of all headers in this object.abstract HttpHeadersRemoves the header with the specified name.static voidremoveHeader(HttpMessage message, String name) Removes the header with the specified name.static voidabstract HttpHeadersSets a header with the specified name and values.abstract HttpHeadersSets a header with the specified name and value.set(HttpHeaders headers) Cleans the current header entries and copies all header entries of the specifiedheaders.static voidset100ContinueExpected(HttpMessage message) Sets the"Expect: 100-continue"header to the specified message.static voidset100ContinueExpected(HttpMessage message, boolean set) Sets or removes the"Expect: 100-continue"header to / from the specified message.static voidsetContentLength(HttpMessage message, long length) Sets the"Content-Length"header.static voidsetDate(HttpMessage message, Date value) Sets the"Date"header.static voidsetDateHeader(HttpMessage message, String name, Iterable<Date> values) Sets a new date header with the specified name and values.static voidsetDateHeader(HttpMessage message, String name, Date value) Sets a new date header with the specified name and value.static voidsetHeader(HttpMessage message, String name, Iterable<?> values) Sets a new header with the specified name and values.static voidsetHeader(HttpMessage message, String name, Object value) Sets a new header with the specified name and value.static voidsetHost(HttpMessage message, String value) Sets the"Host"header.static voidsetIntHeader(HttpMessage message, String name, int value) Sets a new integer header with the specified name and value.static voidsetIntHeader(HttpMessage message, String name, Iterable<Integer> values) Sets a new integer header with the specified name and values.static voidsetKeepAlive(HttpMessage message, boolean keepAlive) Sets the value of the"Connection"header depending on the protocol version of the specified message.static void(package private) static voidvalidateHeaderName(String headerName) Validates the name of a header(package private) static voidvalidateHeaderValue(String headerValue) Validates the specified header value(package private) static voidvalideHeaderNameChar(char c) Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Iterable
forEach, iterator, spliterator
-
Field Details
-
EMPTY_HEADERS
-
-
Constructor Details
-
HttpHeaders
protected HttpHeaders()
-
-
Method Details
-
isKeepAlive
Returnstrueif 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 ofHttpVersion.isKeepAliveDefault(). -
setKeepAlive
Sets the value of the"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 byHttpVersion.isKeepAliveDefault().- If the connection is kept alive by default:
- set to
"close"ifkeepAliveisfalse. - remove otherwise.
- set to
- If the connection is closed by default:
- set to
"keep-alive"ifkeepAliveistrue. - remove otherwise.
- set to
- If the connection is kept alive by default:
-
getHeader
Returns the header value with the specified header name. If there are more than one header value for the specified header name, the first value is returned.- Returns:
- the header value or
nullif there is no such header
-
getHeader
Returns the header value with the specified header name. If there are more than one header value for the specified header name, the first value is returned.- Returns:
- the header value or the
defaultValueif there is no such header
-
setHeader
Sets a new header with the specified name and value. If there is an existing header with the same name, the existing header is removed. If the specified value is not aString, it is converted into aStringbyObject.toString(), except forDateandCalendarwhich are formatted to the date format defined in RFC2616. -
setHeader
Sets a new header with the specified name and values. If there is an existing header with the same name, the existing header is removed. This getMethod can be represented approximately as the following code:removeHeader(message, name); for (Object v: values) { if (v == null) { break; } addHeader(message, name, v); } -
addHeader
-
removeHeader
Removes the header with the specified name. -
clearHeaders
Removes all headers from the specified message. -
getIntHeader
Returns the integer header value with the specified header name. If there are more than one header value for the specified header name, the first value is returned.- Returns:
- the header value
- Throws:
NumberFormatException- if there is no such header or the header value is not a number
-
getIntHeader
Returns the integer header value with the specified header name. If there are more than one header value for the specified header name, the first value is returned.- Returns:
- the header value or the
defaultValueif there is no such header or the header value is not a number
-
setIntHeader
Sets a new integer header with the specified name and value. If there is an existing header with the same name, the existing header is removed. -
setIntHeader
Sets a new integer header with the specified name and values. If there is an existing header with the same name, the existing header is removed. -
addIntHeader
Adds a new integer header with the specified name and value. -
getDateHeader
Returns the date header value with the specified header name. If there are more than one header value for the specified header name, the first value is returned.- Returns:
- the header value
- Throws:
ParseException- if there is no such header or the header value is not a formatted date
-
getDateHeader
Returns the date header value with the specified header name. If there are more than one header value for the specified header name, the first value is returned.- Returns:
- the header value or the
defaultValueif there is no such header or the header value is not a formatted date
-
setDateHeader
Sets a new date header with the specified name and value. If there is an existing header with the same name, the existing header is removed. The specified value is formatted as defined in RFC2616 -
setDateHeader
Sets a new date header with the specified name and values. If there is an existing header with the same name, the existing header is removed. The specified values are formatted as defined in RFC2616 -
addDateHeader
Adds a new date header with the specified name and value. The specified value is formatted as defined in RFC2616 -
getContentLength
Returns the length of the content. Please note that this value is not retrieved fromHttpMessage.getContent()but from the"Content-Length"header, and thus they are independent from each other.- Returns:
- the content length
- Throws:
NumberFormatException- if the message does not have the"Content-Length"header or its value is not a number
-
getContentLength
Returns the length of the content. Please note that this value is not retrieved fromHttpMessage.getContent()but from the"Content-Length"header, and thus they are independent from each other.- Returns:
- the content length or
defaultValueif this message does not have the"Content-Length"header or its value is not a number
-
getWebSocketContentLength
Returns the content length of the specified web socket message. If the specified message is not a web socket message,-1is returned. -
setContentLength
Sets the"Content-Length"header. -
getHost
Returns the value of the"Host"header. -
getHost
Returns the value of the"Host"header. If there is no such header, thedefaultValueis returned. -
setHost
Sets the"Host"header. -
getDate
Returns the value of the"Date"header.- Throws:
ParseException- if there is no such header or the header value is not a formatted date
-
getDate
Returns the value of the"Date"header. If there is no such header or the header is not a formatted date, thedefaultValueis returned. -
setDate
Sets the"Date"header. -
is100ContinueExpected
Returnstrueif and only if the specified message contains the"Expect: 100-continue"header. -
set100ContinueExpected
Sets the"Expect: 100-continue"header to the specified message. If there is any existing"Expect"header, they are replaced with the new one. -
set100ContinueExpected
Sets or removes the"Expect: 100-continue"header to / from the specified message. If the specifiedvalueistrue, the"Expect: 100-continue"header is set and all other previous"Expect"headers are removed. Otherwise, all"Expect"headers are removed completely. -
validateHeaderName
Validates the name of a header- Parameters:
headerName- The header name being validated
-
valideHeaderNameChar
static void valideHeaderNameChar(char c) -
validateHeaderValue
Validates the specified header value- Parameters:
headerValue- The value being validated
-
isTransferEncodingChunked
Checks to see if the transfer encoding in a specifiedHttpMessageis chunked- Parameters:
message- The message to check- Returns:
- True if transfer encoding is chunked, otherwise false
-
removeTransferEncodingChunked
-
setTransferEncodingChunked
-
isContentLengthSet
-
get
Returns 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.- Parameters:
name- The name of the header to search- Returns:
- The first header value or
nullif there is no such header
-
getAll
-
entries
Returns 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, useIterable.iterator()instead, which has much less overhead. -
contains
Checks to see if there is a header with the specified name- Parameters:
name- The name of the header to search for- Returns:
- True if at least one header is found
-
isEmpty
public abstract boolean isEmpty()Checks if no header exists. -
names
Returns 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, useIterable.iterator()instead, which has much less overhead. -
add
Adds 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.- Parameters:
name- The name of the header being addedvalue- The value of the header being added- Returns:
this
-
add
Adds 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); }- Parameters:
name- The name of the headers being setvalues- The values of the headers being set- Returns:
this
-
add
Adds all header entries of the specifiedheaders.- Returns:
this
-
set
Sets 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.- Parameters:
name- The name of the header being setvalue- The value of the header being set- Returns:
this
-
set
Sets 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); }- Parameters:
name- The name of the headers being setvalues- The values of the headers being set- Returns:
this
-
set
Cleans the current header entries and copies all header entries of the specifiedheaders.- Returns:
this
-
remove
Removes the header with the specified name.- Parameters:
name- The name of the header to remove- Returns:
this
-
clear
-
contains
-