org.jboss.netty.handler.codec.http

## Class HttpHeaders

- java.lang.Object
- - org.jboss.netty.handler.codec.http.HttpHeaders

    public class HttpHeaders
    extends Object

Provides the constants for the standard HTTP header names and values and commonly used utility methods that accesses an `HttpMessage`.

### Nested Class Summary

Nested Classes
`static class` `HttpHeaders.Names` Standard HTTP header names.
`static class` `HttpHeaders.Values` Standard HTTP header values.

### Method Summary

Methods
`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 long` `getContentLength(HttpMessage message)` Returns the length of the content.
`static long` `getContentLength(HttpMessage message, long defaultValue)` Returns the length of the content.
`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` `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` `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.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Method Detail

#### isKeepAlive

    public static boolean isKeepAlive(HttpMessage message)

Returns `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()`.

#### setKeepAlive

    public static void setKeepAlive(HttpMessage message,
                    boolean keepAlive)

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 by `HttpVersion.isKeepAliveDefault()`.

- If the connection is kept alive by default:
  - set to `"close"` if `keepAlive` is `false`.
  - remove otherwise.
- If the connection is closed by default:
  - set to `"keep-alive"` if `keepAlive` is `true`.
  - remove otherwise.

#### getHeader

    public static String getHeader(HttpMessage message,
                   String name)

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 `null` if there is no such header

#### getHeader

    public static String getHeader(HttpMessage message,
                   String name,
                   String defaultValue)

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 `defaultValue` if there is no such header

#### setHeader

    public static void setHeader(HttpMessage message,
                 String name,
                 Object value)

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.

#### setHeader

    public static void setHeader(HttpMessage message,
                 String name,
                 Iterable<?> values)

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.

#### addHeader

    public static void addHeader(HttpMessage message,
                 String name,
                 Object value)

Adds a new header with the specified name and value.

#### getIntHeader

    public static int getIntHeader(HttpMessage message,
                   String name)

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

    public static int getIntHeader(HttpMessage message,
                   String name,
                   int defaultValue)

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 `defaultValue` if there is no such header or the header value is not a number

#### setIntHeader

    public static void setIntHeader(HttpMessage message,
                    String name,
                    int value)

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

    public static void setIntHeader(HttpMessage message,
                    String name,
                    Iterable<Integer> values)

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

    public static void addIntHeader(HttpMessage message,
                    String name,
                    int value)

Adds a new integer header with the specified name and value.

#### getContentLength

    public static long getContentLength(HttpMessage message)

Returns the length of the content. Please note that this value is not retrieved from `HttpMessage.getContent()` but from the `"Content-Length"` header, and thus they are independent from each other.

Returns:
  the content length or `0` if this message does not have the `"Content-Length"` header

#### getContentLength

    public static long getContentLength(HttpMessage message,
                        long defaultValue)

Returns the length of the content. Please note that this value is not retrieved from `HttpMessage.getContent()` but from the `"Content-Length"` header, and thus they are independent from each other.

Returns:
  the content length or `defaultValue` if this message does not have the `"Content-Length"` header

#### setContentLength

    public static void setContentLength(HttpMessage message,
                        long length)

Sets the `"Content-Length"` header.

#### getHost

    public static String getHost(HttpMessage message)

Returns the value of the `"Host"` header.

#### getHost

    public static String getHost(HttpMessage message,
                 String defaultValue)

Returns the value of the `"Host"` header. If there is no such header, the `defaultValue` is returned.

#### setHost

    public static void setHost(HttpMessage message,
               String value)

Sets the `"Host"` header.

#### is100ContinueExpected

    public static boolean is100ContinueExpected(HttpMessage message)

Returns `true` if and only if the specified message contains the `"Expect: 100-continue"` header.

#### set100ContinueExpected

    public static void set100ContinueExpected(HttpMessage message)

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

    public static void set100ContinueExpected(HttpMessage message,
                              boolean set)

Sets or removes the `"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.