simple.http
Interface GenericHeader

All Known Subinterfaces:
Request, Response
All Known Implementing Classes:
FilterRequest, FilterResponse

public interface GenericHeader

This is a GenericHeader object that can be used to represent the headers that can be found in a HTTP message header. This can be used to access the HTTP message headers conveniently.

This does not include the request and status line of a request or response. The GenericHeader is used to represent the set of headers of the form "Header-Name: header-value".

Author:
Niall Gallagher

Method Summary
 void add(java.lang.String name, int value)
          This can be used to add a HTTP message header to this object.
 void add(java.lang.String name, java.lang.String value)
          This can be used to add a HTTP message header to this object.
 void addDate(java.lang.String name, long date)
          This is used as a convenience method for adding a header that needs to be parsed into a HTTP-date string.
 void clear()
          This is used to clear all HTTP message headers from the message header.
 boolean contains(java.lang.String name)
          This is used to see if there is a HTTP message header with the given name in this container.
 boolean contains(java.lang.String name, java.lang.String value)
          This is used to see if there is a HTTP message header with the given name in this container, if it exists this will check to see if the provided value exists.
 long getDate(int off)
          This can be used to get the value of the HTTP message header at the specified index.
 long getDate(java.lang.String name)
          This can be used to get the date of the first message header that has the specified name.
 java.lang.String getName(int off)
          This is used to get the name value of the HTTP message header at the specified index.
 java.lang.String getValue(int off)
          This is used to get the text value of the HTTP message header at the specified index.
 java.lang.String getValue(java.lang.String name)
          This can be used to get the value of the first message header that has the specified name.
 java.lang.String[] getValues(java.lang.String name)
          This can be used to get the values of HTTP message headers that have the specified name.
 int headerCount()
          This can be used to determine how many HTTP message headers this object contains.
 int indexOf(java.lang.String name)
          This can be used to find the first occurrence of the specified HTTP message header.
 int indexOf(java.lang.String name, int from)
          This can be used to find the first occurrence of the specified HTTP message header from a given index.
 void remove(int off)
          This can be used to remove the HTTP message header at the specified index.
 void removeAll(java.lang.String name)
          This can be used to remove all HTTP message headers with the specified name.
 void set(java.lang.String name, int value)
          This can be used to set a HTTP message header to this object.
 void set(java.lang.String name, java.lang.String value)
          This can be used to set a HTTP message header to this object.
 void setDate(java.lang.String name, long date)
          This is used as a convenience method for setting a header that needs to be parsed into a HTTP-date string.
 

Method Detail

headerCount

int headerCount()
This can be used to determine how many HTTP message headers this object contains. The headerCount represents the number of individual HTTP message headers that this has.

Returns:
returns the number of HTTP message headers this has

indexOf

int indexOf(java.lang.String name)
This can be used to find the first occurrence of the specified HTTP message header. This will search through the list of HTTP message headers that this contains and when it encounters a HTTP message header with the name specified it returns the index of that HTTP message header. The index will change when a remove is used. So the index is valid only for the until the next remove method or possible the next add method.

Parameters:
name - name of the HTTP message header being searched for
Returns:
returns the position of the first HTTP message header

indexOf

int indexOf(java.lang.String name,
            int from)
This can be used to find the first occurrence of the specified HTTP message header from a given index. This will search through the list of HTTP message headers that occur after the index. When it encounters a HTTP message header with the name specified it returns the index of that HTTP message header. The index will change when a remove is used. So the index is valid only until a remove or add method is used.

Parameters:
name - name of the HTTP message header being searched for
from - the index from which the search will start
Returns:
this returns the position of the HTTP message header

add

void add(java.lang.String name,
         java.lang.String value)
This can be used to add a HTTP message header to this object. The name and value of the HTTP message header will be used to create a HTTP message header object which can be retrieved using the indexOf in combination with the get methods.

Parameters:
name - the name of the HTTP message header to be added
value - the value the HTTP message header will have

set

void set(java.lang.String name,
         java.lang.String value)
This can be used to set a HTTP message header to this object. The name and value of the HTTP message header will be used to create a HTTP message header object which can be retrieved using the indexOf in combination with the get methods. This will perform a removeAll using the issued header name before the header value is set.

Parameters:
name - the name of the HTTP message header to be added
value - the value the HTTP message header will have

add

void add(java.lang.String name,
         int value)
This can be used to add a HTTP message header to this object. The name and value of the HTTP message header will be used to create a HTTP message header object which can be retrieved using the indexOf in combination with the get methods.

Parameters:
name - the name of the HTTP message header to be added
value - the value the HTTP message header will have

set

void set(java.lang.String name,
         int value)
This can be used to set a HTTP message header to this object. The name and value of the HTTP message header will be used to create a HTTP message header object which can be retrieved using the indexOf in combination with the get methods. This will perform a removeAll using the issued header name before the header value is set.

Parameters:
name - the name of the HTTP message header to be added
value - the value the HTTP message header will have

addDate

void addDate(java.lang.String name,
             long date)
This is used as a convenience method for adding a header that needs to be parsed into a HTTP-date string. This will convert the date given into a date string defined in RFC 2616 sec 3.3.1.

Parameters:
name - the name of the HTTP message header to be added
date - the value the HTTP message header will have when parsed into RFC 1123 format

setDate

void setDate(java.lang.String name,
             long date)
This is used as a convenience method for setting a header that needs to be parsed into a HTTP-date string. This will convert the date given into a date string defined in RFC 2616 sec 3.3.1. This will perform a removeAll using the issued header name before the header value is set.

Parameters:
name - the name of the HTTP message header to be added
date - the value the HTTP message header will have when parsed into RFC 1123 format

remove

void remove(int off)
This can be used to remove the HTTP message header at the specified index. This will invalidate any value received by an indexOf method previous to this. If the index specified is not valid then an IndexOutOfBoundsException may be thrown.

Parameters:
off - index of the HTTP message header to be removed

removeAll

void removeAll(java.lang.String name)
This can be used to remove all HTTP message headers with the specified name. This will search through the list of HTTP message header an remove the HTTP message headers from the list. This will invalidate any previous indexes received.

Parameters:
name - name of the message headers to be removed

getValue

java.lang.String getValue(int off)
This is used to get the text value of the HTTP message header at the specified index. This is a convenience method that avoids having to deal with a HTTP message header object. If the offset used specified is invalid then an exception may be thrown.

Parameters:
off - the offset of the HTTP message header value
Returns:
this returns the text value value that the header

getName

java.lang.String getName(int off)
This is used to get the name value of the HTTP message header at the specified index. This is used in conjunction with the getValue(int) method so that the contents of the HTTP message header can be fully examined.

Parameters:
off - the offset of the HTTP message header name value
Returns:
this returns the name of the header at that index

getDate

long getDate(int off)
This can be used to get the value of the HTTP message header at the specified index. This is a convenience method that avoids having to deal with a HTTP message header object. If the offset used specified is invalid then an exception may be thrown.

Parameters:
off - the offset of the date HTTP message header value
Returns:
this returns the date as a long from the parsed value of that HTTP message header

getValue

java.lang.String getValue(java.lang.String name)
This can be used to get the value of the first message header that has the specified name. This is a convenience method that avoids having to deal with a HTTP message header object and the indexOf methods. This returns null if theres not a HTTP message header.

Parameters:
name - the HTTP message header to get the value from
Returns:
this returns the value that the HTTP message header

getValues

java.lang.String[] getValues(java.lang.String name)
This can be used to get the values of HTTP message headers that have the specified name. This is a convenience method that will present that values as tokens extracted from the header. This has obvious performance benifits as it avoids having to deal with substring and trim calls.

The tokens returned by this method are ordered according to there HTTP quality values, or "q" values, see RFC 2616 section 3.9. This also strips out the quality parameter from tokens returned. So "image/html; q=0.9" results in "image/html". If there are no "q" values present then order is by appearence.

The result from this is either the trimmed header value, that is, the header value with no leading or trailing whitespace or an array of trimmed tokens ordered with the most preferred in the lower indexes, so index 0 is has higest preference.

Parameters:
name - the name of the headers that are to be retrieved
Returns:
ordered array of tokens extracted from the header(s)

getDate

long getDate(java.lang.String name)
This can be used to get the date of the first message header that has the specified name. This is a convenience method that avoids having to deal with parsing the value of the requested HTTP message header. This also avoids having to deal with the indexOf methods. This returns -1 if theres not a HTTP message header.

Parameters:
name - the HTTP message header to get the value from
Returns:
this returns the date as a long from the parsed value of that HTTP message header

contains

boolean contains(java.lang.String name)
This is used to see if there is a HTTP message header with the given name in this container. If there is a HTTP message header with the specified name then this returns true otherwise false.

Parameters:
name - the HTTP message header to get the value from
Returns:
this returns true if the HTTP message header exists

contains

boolean contains(java.lang.String name,
                 java.lang.String value)
This is used to see if there is a HTTP message header with the given name in this container, if it exists this will check to see if the provided value exists. This is used for a comma seperated list of values found within the HTTP header value. If the header and token exits this returns true otherwise false.

Parameters:
name - the HTTP message header to get the value from
value - this value to find within the HTTP value
Returns:
this returns true if the HTTP message value exists

clear

void clear()
This is used to clear all HTTP message headers from the message header. This will leave no data remaining, i.e. headerCount is zero after this method is invoked, this is a convenience method.