ikrs.httpd
Class HTTPHeaders

java.lang.Object
  extended by ikrs.httpd.HTTPHeaders

public class HTTPHeaders
extends java.lang.Object

This class wraps HTTPHeaderLines together into a list like searchable structure.


Field Summary
static java.lang.String NAME_ACCEPT
           
static java.lang.String NAME_ACCEPT_CHARSET
           
static java.lang.String NAME_ACCEPT_ENCODING
           
static java.lang.String NAME_ACCEPT_LANGUAGE
           
static java.lang.String NAME_ALLOW
           
static java.lang.String NAME_CONNECTION
           
static java.lang.String NAME_CONTENT_DISPOSITION
           
static java.lang.String NAME_CONTENT_LENGTH
           
static java.lang.String NAME_CONTENT_RANGE
           
static java.lang.String NAME_CONTENT_TYPE
           
static java.lang.String NAME_COOKIE
           
static java.lang.String NAME_HOST
           
static java.lang.String NAME_REFERER
           
static java.lang.String NAME_USER_AGENT
           
static java.lang.String NAME_WWW_AUTHENTICATE
           
 
Constructor Summary
HTTPHeaders()
          Creates a new and empty HTTPHeaders instance.
 
Method Summary
 boolean add(HTTPHeaderLine e)
          This method adds a new header line to this headers object.
 boolean add(HTTPHeaderLine e, boolean replaceIfExists)
           
 boolean add(java.lang.String key, java.lang.String value)
          This method adds a new header line to this headers object.
 HTTPHeaderLine get(int index)
           
 HTTPHeaderLine get(java.lang.String name)
          This method returns a random header line with the given key or null if no such element can be found.
 java.util.Set<HTTPHeaderLine> getAll(java.lang.String name)
          This method returns a set containing all header lines with the given key (name).
 java.lang.Long getLongValue(java.lang.String key)
           
 java.lang.String getRequestMethod()
           
 java.lang.String getRequestProtocol()
           
 java.lang.String getRequestURI()
           
 java.lang.String getRequestVersion()
           
 java.lang.String getResponseReasonPhrase()
           
 java.lang.String getResponseStatus()
           
 java.lang.String getStringValue(java.lang.String key)
           
 boolean isGETRequest()
          This method checks if the headers represent a HTTP GET request.
 boolean isHEADRequest()
          This method checks if the headers represent a HTTP HEAD request.
 boolean isOPTIONSRequest()
          This method checks if the headers represent a HTTP OPTIONS request.
 boolean isPOSTRequest()
          This method checks if the headers represent a HTTP POST request.
 boolean isTRACERequest()
          This method checks if the headers represent a HTTP TRACE request.
 java.util.Iterator<HTTPHeaderLine> iterator()
           
static HTTPHeaders read(java.io.InputStream in)
           
 boolean remove(java.lang.String name)
          This method removes max.
 int removeAll(java.lang.String name)
          This method removes *all* header lines with the given key (name).
 int replaceAll(HTTPHeaderLine element)
          This method replaces all existing header lines matching the passed line's key by the passed line itself.
 boolean replaceResponseLine(HTTPHeaderLine statusLine)
           
 int size()
           
 java.lang.String toString()
           
 java.lang.StringBuffer toString(java.lang.StringBuffer b)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NAME_ACCEPT

public static final java.lang.String NAME_ACCEPT
See Also:
Constant Field Values

NAME_ACCEPT_CHARSET

public static final java.lang.String NAME_ACCEPT_CHARSET
See Also:
Constant Field Values

NAME_ACCEPT_ENCODING

public static final java.lang.String NAME_ACCEPT_ENCODING
See Also:
Constant Field Values

NAME_ACCEPT_LANGUAGE

public static final java.lang.String NAME_ACCEPT_LANGUAGE
See Also:
Constant Field Values

NAME_CONNECTION

public static final java.lang.String NAME_CONNECTION
See Also:
Constant Field Values

NAME_CONTENT_DISPOSITION

public static final java.lang.String NAME_CONTENT_DISPOSITION
See Also:
Constant Field Values

NAME_CONTENT_LENGTH

public static final java.lang.String NAME_CONTENT_LENGTH
See Also:
Constant Field Values

NAME_CONTENT_RANGE

public static final java.lang.String NAME_CONTENT_RANGE
See Also:
Constant Field Values

NAME_CONTENT_TYPE

public static final java.lang.String NAME_CONTENT_TYPE
See Also:
Constant Field Values

NAME_COOKIE

public static final java.lang.String NAME_COOKIE
See Also:
Constant Field Values

NAME_HOST

public static final java.lang.String NAME_HOST
See Also:
Constant Field Values

NAME_REFERER

public static final java.lang.String NAME_REFERER
See Also:
Constant Field Values

NAME_USER_AGENT

public static final java.lang.String NAME_USER_AGENT
See Also:
Constant Field Values

NAME_ALLOW

public static final java.lang.String NAME_ALLOW
See Also:
Constant Field Values

NAME_WWW_AUTHENTICATE

public static final java.lang.String NAME_WWW_AUTHENTICATE
See Also:
Constant Field Values
Constructor Detail

HTTPHeaders

public HTTPHeaders()
Creates a new and empty HTTPHeaders instance.

Method Detail

getStringValue

public java.lang.String getStringValue(java.lang.String key)

getLongValue

public java.lang.Long getLongValue(java.lang.String key)

isGETRequest

public boolean isGETRequest()
This method checks if the headers represent a HTTP GET request. If no respective header is present (should not happen) the method returns false.

Returns:
true If the representing request is a HTTP GET request, false otherwise.

isPOSTRequest

public boolean isPOSTRequest()
This method checks if the headers represent a HTTP POST request. If no respective header is present (should not happen) the method returns false.

Returns:
true If the representing request is a HTTP POST request, false otherwise.

isOPTIONSRequest

public boolean isOPTIONSRequest()
This method checks if the headers represent a HTTP OPTIONS request. If no respective header is present (should not happen) the method returns false.

Returns:
true If the representing request is a HTTP OPTIONS request, false otherwise.

isHEADRequest

public boolean isHEADRequest()
This method checks if the headers represent a HTTP HEAD request. If no HTTP* header is present the method returns false.

Returns:
true If the representing request is a HTTP HEAD request, false otherwise.

isTRACERequest

public boolean isTRACERequest()
This method checks if the headers represent a HTTP TRACE request. If no respective header is present (should not happen) the method returns false.

Returns:
true If the representing request is a HTTP TRACE request, false otherwise.

replaceResponseLine

public boolean replaceResponseLine(HTTPHeaderLine statusLine)
                            throws java.lang.NullPointerException,
                                   HeaderFormatException
Throws:
java.lang.NullPointerException
HeaderFormatException

getAll

public java.util.Set<HTTPHeaderLine> getAll(java.lang.String name)
                                     throws java.lang.NullPointerException
This method returns a set containing all header lines with the given key (name). The returned set is a full copy and is not backed up the the underlying structure, so modifications on the set have no effect to this HTTPHeaders instance.

Parameters:
name - The desired headers' name (the key; must not be null).
Returns:
A newly created set containing all header lines with the given name.
Throws:
java.lang.NullPointerException - If name is null.

get

public HTTPHeaderLine get(java.lang.String name)
                   throws java.lang.NullPointerException
This method returns a random header line with the given key or null if no such element can be found. If there are multiple header lines with the same key one element is randomly picked.

Parameters:
name - The desired header line's name (key; must not be null).
Returns:
A header line with the given name.
Throws:
java.lang.NullPointerException - If name is null.

add

public boolean add(java.lang.String key,
                   java.lang.String value)
            throws java.lang.NullPointerException
This method adds a new header line to this headers object. This method just calls add( new HTTPHeaderLine(key,value) ).

Parameters:
key - The new line's key.
value - Thw new line's value.
Throws:
java.lang.NullPointerException - If the key is null.

add

public boolean add(HTTPHeaderLine e)
            throws java.lang.NullPointerException
This method adds a new header line to this headers object. If the passed line is the HTTP response status line, the old line will be replaced.

Parameters:
key - The new line's key.
Throws:
java.lang.NullPointerException - If the line is null.

add

public boolean add(HTTPHeaderLine e,
                   boolean replaceIfExists)

remove

public boolean remove(java.lang.String name)
               throws java.lang.NullPointerException
This method removes max. one header line with the given key (name). If no such line can be found the internal list is left unchanged and the method return false (true otherwise).

Parameters:
name - The header line's name (key).
Returns:
True if (and only if) the passed header-line's name was found and removed, false otherwise.
Throws:
java.lang.NullPointerException - If the passed name is null.

removeAll

public int removeAll(java.lang.String name)
              throws java.lang.NullPointerException
This method removes *all* header lines with the given key (name). The returned integer indicates the number of removed lines.

Parameters:
name - The header line's name (key).
Returns:
The number of removed header lines.
Throws:
java.lang.NullPointerException - If the passed name is null.

replaceAll

public int replaceAll(HTTPHeaderLine element)
               throws java.lang.NullPointerException
This method replaces all existing header lines matching the passed line's key by the passed line itself. After calling this method this HTTPHeaders-instance contains _exactly_ one element with the passed line's key. The returned integer indicates the number of lines that have been removed (old element count).

Parameters:
element - The header line you want to use as replacement (replacing all existing lines with the same key).
Returns:
The number of elements that were replaced (old element count).
Throws:
java.lang.NullPointerException - If the passed element is null.

get

public HTTPHeaderLine get(int index)
                   throws java.lang.IndexOutOfBoundsException
Throws:
java.lang.IndexOutOfBoundsException

iterator

public java.util.Iterator<HTTPHeaderLine> iterator()

size

public int size()

getRequestMethod

public java.lang.String getRequestMethod()

getRequestProtocol

public java.lang.String getRequestProtocol()

getRequestVersion

public java.lang.String getRequestVersion()

getRequestURI

public java.lang.String getRequestURI()

getResponseStatus

public java.lang.String getResponseStatus()

getResponseReasonPhrase

public java.lang.String getResponseReasonPhrase()

read

public static HTTPHeaders read(java.io.InputStream in)
                        throws java.io.EOFException,
                               java.io.IOException
Throws:
java.io.EOFException
java.io.IOException

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

toString

public java.lang.StringBuffer toString(java.lang.StringBuffer b)