org.mortbay.http
Class HttpFields

java.lang.Object
  |
  +--org.mortbay.http.HttpFields

public class HttpFields
extends java.lang.Object

HTTP Fields. A collection of HTTP header and or Trailer fields. This class is not synchronized and needs to be protected from concurrent access. This class is not synchronized as it is expected that modifications will only be performed by a single thread.

Version:
$Id: HttpFields.java,v 1.50.2.10 2004/03/30 10:33:29 gregwilkins Exp $
Author:
Greg Wilkins (gregw)

Nested Class Summary
 class HttpFields.Entry
           
 
Field Summary
static java.lang.String __01Jan1970
           
static java.lang.String __Accept
          Request Fields.
static java.lang.String __AcceptCharset
          Request Fields.
static java.lang.String __AcceptEncoding
          Request Fields.
static java.lang.String __AcceptLanguage
          Request Fields.
static java.lang.String __AcceptRanges
          Response Fields.
static java.lang.String __Age
          Response Fields.
static java.lang.String __Allow
          Entity Fields.
static java.lang.String __Authorization
          Request Fields.
static java.lang.String __CacheControl
          General Fields.
static java.lang.String __Chunked
          Fields Values.
static java.lang.String __Close
           
static char[] __COLON
           
static java.lang.String __Connection
          General Fields.
static java.lang.String __ContentEncoding
          Entity Fields.
static java.lang.String __ContentLanguage
          Entity Fields.
static java.lang.String __ContentLength
          Entity Fields.
static java.lang.String __ContentLocation
          Entity Fields.
static java.lang.String __ContentMD5
          Entity Fields.
static java.lang.String __ContentRange
          Entity Fields.
static java.lang.String __ContentType
          Entity Fields.
static java.lang.String __Cookie
          Other Fields.
static char[] __CRLF
           
static java.lang.String __Date
          General Fields.
static DateCache __dateCache
           
static java.lang.ThreadLocal __dateReceiveCache
           
static java.text.SimpleDateFormat[] __dateReceiveSource
           
static java.lang.String __ETag
          Response Fields.
static java.lang.String __Expect
          Request Fields.
static java.lang.String __ExpectContinue
           
static java.lang.String __Expires
          Entity Fields.
static java.lang.String __Forwarded
          Request Fields.
static java.lang.String __From
          Request Fields.
static java.util.TimeZone __GMT
           
static java.lang.String __Host
          Request Fields.
static java.lang.String __Identity
          Other Fields.
static java.lang.String __IfMatch
          Request Fields.
static java.lang.String __IfModifiedSince
          Request Fields.
static java.lang.String __IfNoneMatch
          Request Fields.
static java.lang.String __IfRange
          Request Fields.
static java.lang.String __IfUnmodifiedSince
          Request Fields.
static java.lang.String __KeepAlive
          Request Fields.
static java.lang.String __LastModified
          Entity Fields.
static java.lang.String __Location
          Response Fields.
static java.lang.String __MaxForwards
          Request Fields.
static java.lang.String __MessageHttp
           
static java.lang.String __MimeVersion
          Other Fields.
static java.lang.String __Pragma
          General Fields.
static java.lang.String __ProxyAuthenticate
          Response Fields.
static java.lang.String __ProxyAuthorization
          Request Fields.
static java.lang.String __ProxyConnection
          General Fields.
static java.lang.String __Range
          Request Fields.
static java.lang.String __Referer
          Request Fields.
static java.lang.String __RequestRange
          Request Fields.
static java.lang.String __RetryAfter
          Response Fields.
static java.lang.String __separators
           
static java.lang.String __Server
          Response Fields.
static java.lang.String __ServletEngine
          Response Fields.
static java.lang.String __SetCookie
          Other Fields.
static java.lang.String __SetCookie2
          Other Fields.
static java.lang.String __SoapAction
          Other Fields.
static java.lang.String __TE
          Request Fields.
static java.lang.String __TextHtml
           
static java.lang.String __Trailer
          General Fields.
static java.lang.String __TransferEncoding
          General Fields.
static java.lang.String __Upgrade
          General Fields.
static java.lang.String __UserAgent
          Request Fields.
static java.lang.String __Vary
          Response Fields.
static java.lang.String __Via
          General Fields.
static java.lang.String __Warning
          General Fields.
static java.lang.String __WwwAuthenticate
          Response Fields.
static java.lang.String __WwwFormUrlEncode
           
static java.lang.String __XForwardedFor
          Request Fields.
 
Constructor Summary
HttpFields()
          Constructor.
 
Method Summary
 void add(HttpFields fields)
          Add fields from another HttpFields instance.
 void add(java.lang.String name, java.lang.String value)
          Add to or set a field.
 void addDateField(java.lang.String name, java.util.Date date)
          Adds the value of a date field.
 void addDateField(java.lang.String name, long date)
          Adds the value of a date field.
 void addSetCookie(Cookie cookie, boolean cookie2)
          Format a set cookie value
 void clear()
          Clear the header.
 boolean containsKey(java.lang.String name)
           
 void destroy()
          Destroy the header.
static java.lang.String formatDate(java.util.Calendar calendar, boolean cookie)
          Format HTTP date "EEE, dd MMM yyyy HH:mm:ss 'GMT'" or "EEE, dd-MMM-yy HH:mm:ss 'GMT'"for cookies
static java.lang.String formatDate(long date, boolean cookie)
          Format HTTP date "EEE, dd MMM yyyy HH:mm:ss 'GMT'" or "EEE, dd-MMM-yy HH:mm:ss 'GMT'"for cookies
static void formatDate(java.lang.StringBuffer buf, java.util.Calendar calendar, boolean cookie)
          Format HTTP date "EEE, dd MMM yyyy HH:mm:ss 'GMT'" or "EEE, dd-MMM-yy HH:mm:ss 'GMT'"for cookies
static java.lang.String formatDate(java.lang.StringBuffer buf, long date, boolean cookie)
          Format HTTP date "EEE, dd MMM yyyy HH:mm:ss 'GMT'" or "EEE, dd-MMM-yy HH:mm:ss 'GMT'"for cookies
 java.lang.String get(java.lang.String name)
           
 long getDateField(java.lang.String name)
          Get a header as a date value.
 java.util.Enumeration getFieldNames()
          Get enumeration of header _names.
 int getIntField(java.lang.String name)
          Get a header as an integer value.
static java.lang.Float getQuality(java.lang.String value)
           
 java.util.Enumeration getValues(java.lang.String name)
          Get multi headers
 java.util.Enumeration getValues(java.lang.String name, java.lang.String separators)
          Get multi field values with separator.
 java.util.Iterator iterator()
          return an iterator for field name:value pairs
 void put(java.lang.String name, java.util.List list)
          Set a field.
 java.lang.String put(java.lang.String name, java.lang.String value)
          Set a field.
 void putDateField(java.lang.String name, java.util.Date date)
          Sets the value of a date field.
 void putDateField(java.lang.String name, long date)
          Sets the value of a date field.
 void putIntField(java.lang.String name, int value)
          Sets the value of an integer field.
static java.util.List qualityList(java.util.Enumeration enum)
          List values in quality order.
 void read(LineInput in)
          Read HttpHeaders from inputStream.
 java.lang.String remove(java.lang.String name)
          Remove a field.
 int size()
           
 java.lang.String toString()
           
static java.lang.String valueParameters(java.lang.String value, java.util.Map parameters)
          Get field value parameters.
 void write(java.io.Writer writer)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

__CacheControl

public static final java.lang.String __CacheControl
General Fields.

See Also:
Constant Field Values

__Connection

public static final java.lang.String __Connection
General Fields.

See Also:
Constant Field Values

__Date

public static final java.lang.String __Date
General Fields.

See Also:
Constant Field Values

__Pragma

public static final java.lang.String __Pragma
General Fields.

See Also:
Constant Field Values

__ProxyConnection

public static final java.lang.String __ProxyConnection
General Fields.

See Also:
Constant Field Values

__Trailer

public static final java.lang.String __Trailer
General Fields.

See Also:
Constant Field Values

__TransferEncoding

public static final java.lang.String __TransferEncoding
General Fields.

See Also:
Constant Field Values

__Upgrade

public static final java.lang.String __Upgrade
General Fields.

See Also:
Constant Field Values

__Via

public static final java.lang.String __Via
General Fields.

See Also:
Constant Field Values

__Warning

public static final java.lang.String __Warning
General Fields.

See Also:
Constant Field Values

__Allow

public static final java.lang.String __Allow
Entity Fields.

See Also:
Constant Field Values

__ContentEncoding

public static final java.lang.String __ContentEncoding
Entity Fields.

See Also:
Constant Field Values

__ContentLanguage

public static final java.lang.String __ContentLanguage
Entity Fields.

See Also:
Constant Field Values

__ContentLength

public static final java.lang.String __ContentLength
Entity Fields.

See Also:
Constant Field Values

__ContentLocation

public static final java.lang.String __ContentLocation
Entity Fields.

See Also:
Constant Field Values

__ContentMD5

public static final java.lang.String __ContentMD5
Entity Fields.

See Also:
Constant Field Values

__ContentRange

public static final java.lang.String __ContentRange
Entity Fields.

See Also:
Constant Field Values

__ContentType

public static final java.lang.String __ContentType
Entity Fields.

See Also:
Constant Field Values

__Expires

public static final java.lang.String __Expires
Entity Fields.

See Also:
Constant Field Values

__LastModified

public static final java.lang.String __LastModified
Entity Fields.

See Also:
Constant Field Values

__Accept

public static final java.lang.String __Accept
Request Fields.

See Also:
Constant Field Values

__AcceptCharset

public static final java.lang.String __AcceptCharset
Request Fields.

See Also:
Constant Field Values

__AcceptEncoding

public static final java.lang.String __AcceptEncoding
Request Fields.

See Also:
Constant Field Values

__AcceptLanguage

public static final java.lang.String __AcceptLanguage
Request Fields.

See Also:
Constant Field Values

__Authorization

public static final java.lang.String __Authorization
Request Fields.

See Also:
Constant Field Values

__Expect

public static final java.lang.String __Expect
Request Fields.

See Also:
Constant Field Values

__Forwarded

public static final java.lang.String __Forwarded
Request Fields.

See Also:
Constant Field Values

__From

public static final java.lang.String __From
Request Fields.

See Also:
Constant Field Values

__Host

public static final java.lang.String __Host
Request Fields.

See Also:
Constant Field Values

__IfMatch

public static final java.lang.String __IfMatch
Request Fields.

See Also:
Constant Field Values

__IfModifiedSince

public static final java.lang.String __IfModifiedSince
Request Fields.

See Also:
Constant Field Values

__IfNoneMatch

public static final java.lang.String __IfNoneMatch
Request Fields.

See Also:
Constant Field Values

__IfRange

public static final java.lang.String __IfRange
Request Fields.

See Also:
Constant Field Values

__IfUnmodifiedSince

public static final java.lang.String __IfUnmodifiedSince
Request Fields.

See Also:
Constant Field Values

__KeepAlive

public static final java.lang.String __KeepAlive
Request Fields.

See Also:
Constant Field Values

__MaxForwards

public static final java.lang.String __MaxForwards
Request Fields.

See Also:
Constant Field Values

__ProxyAuthorization

public static final java.lang.String __ProxyAuthorization
Request Fields.

See Also:
Constant Field Values

__Range

public static final java.lang.String __Range
Request Fields.

See Also:
Constant Field Values

__RequestRange

public static final java.lang.String __RequestRange
Request Fields.

See Also:
Constant Field Values

__Referer

public static final java.lang.String __Referer
Request Fields.

See Also:
Constant Field Values

__TE

public static final java.lang.String __TE
Request Fields.

See Also:
Constant Field Values

__UserAgent

public static final java.lang.String __UserAgent
Request Fields.

See Also:
Constant Field Values

__XForwardedFor

public static final java.lang.String __XForwardedFor
Request Fields.

See Also:
Constant Field Values

__AcceptRanges

public static final java.lang.String __AcceptRanges
Response Fields.

See Also:
Constant Field Values

__Age

public static final java.lang.String __Age
Response Fields.

See Also:
Constant Field Values

__ETag

public static final java.lang.String __ETag
Response Fields.

See Also:
Constant Field Values

__Location

public static final java.lang.String __Location
Response Fields.

See Also:
Constant Field Values

__ProxyAuthenticate

public static final java.lang.String __ProxyAuthenticate
Response Fields.

See Also:
Constant Field Values

__RetryAfter

public static final java.lang.String __RetryAfter
Response Fields.

See Also:
Constant Field Values

__Server

public static final java.lang.String __Server
Response Fields.

See Also:
Constant Field Values

__ServletEngine

public static final java.lang.String __ServletEngine
Response Fields.

See Also:
Constant Field Values

__Vary

public static final java.lang.String __Vary
Response Fields.

See Also:
Constant Field Values

__WwwAuthenticate

public static final java.lang.String __WwwAuthenticate
Response Fields.

See Also:
Constant Field Values

__Cookie

public static final java.lang.String __Cookie
Other Fields.

See Also:
Constant Field Values

__SetCookie

public static final java.lang.String __SetCookie
Other Fields.

See Also:
Constant Field Values

__SetCookie2

public static final java.lang.String __SetCookie2
Other Fields.

See Also:
Constant Field Values

__MimeVersion

public static final java.lang.String __MimeVersion
Other Fields.

See Also:
Constant Field Values

__Identity

public static final java.lang.String __Identity
Other Fields.

See Also:
Constant Field Values

__SoapAction

public static final java.lang.String __SoapAction
Other Fields.

See Also:
Constant Field Values

__Chunked

public static final java.lang.String __Chunked
Fields Values.

See Also:
Constant Field Values

__Close

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

__TextHtml

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

__MessageHttp

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

__WwwFormUrlEncode

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

__ExpectContinue

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

__separators

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

__CRLF

public static final char[] __CRLF

__COLON

public static final char[] __COLON

__GMT

public static java.util.TimeZone __GMT

__dateCache

public static final DateCache __dateCache

__dateReceiveSource

public static java.text.SimpleDateFormat[] __dateReceiveSource

__dateReceiveCache

public static java.lang.ThreadLocal __dateReceiveCache

__01Jan1970

public static final java.lang.String __01Jan1970
Constructor Detail

HttpFields

public HttpFields()
Constructor.

Method Detail

formatDate

public static java.lang.String formatDate(long date,
                                          boolean cookie)
Format HTTP date "EEE, dd MMM yyyy HH:mm:ss 'GMT'" or "EEE, dd-MMM-yy HH:mm:ss 'GMT'"for cookies


formatDate

public static java.lang.String formatDate(java.util.Calendar calendar,
                                          boolean cookie)
Format HTTP date "EEE, dd MMM yyyy HH:mm:ss 'GMT'" or "EEE, dd-MMM-yy HH:mm:ss 'GMT'"for cookies


formatDate

public static java.lang.String formatDate(java.lang.StringBuffer buf,
                                          long date,
                                          boolean cookie)
Format HTTP date "EEE, dd MMM yyyy HH:mm:ss 'GMT'" or "EEE, dd-MMM-yy HH:mm:ss 'GMT'"for cookies


formatDate

public static void formatDate(java.lang.StringBuffer buf,
                              java.util.Calendar calendar,
                              boolean cookie)
Format HTTP date "EEE, dd MMM yyyy HH:mm:ss 'GMT'" or "EEE, dd-MMM-yy HH:mm:ss 'GMT'"for cookies


size

public int size()

getFieldNames

public java.util.Enumeration getFieldNames()
Get enumeration of header _names. Returns an enumeration of strings representing the header _names for this request.


containsKey

public boolean containsKey(java.lang.String name)

get

public java.lang.String get(java.lang.String name)
Parameters:
name - the case-insensitive field name
Returns:
the value of a field, or null if not found. For multiple fields of the same name, only the first is returned.

getValues

public java.util.Enumeration getValues(java.lang.String name)
Get multi headers

Parameters:
name - the case-insensitive field name
Returns:
Enumeration of the values, or null if no such header.

getValues

public java.util.Enumeration getValues(java.lang.String name,
                                       java.lang.String separators)
Get multi field values with separator. The multiple values can be represented as separate headers of the same name, or by a single header using the separator(s), or a combination of both. Separators may be quoted.

Parameters:
name - the case-insensitive field name
separators - String of separators.
Returns:
Enumeration of the values, or null if no such header.

put

public java.lang.String put(java.lang.String name,
                            java.lang.String value)
Set a field.

Parameters:
name - the name of the field
value - the value of the field. If null the field is cleared.

put

public void put(java.lang.String name,
                java.util.List list)
Set a field.

Parameters:
name - the name of the field
list - the List value of the field. If null the field is cleared.

add

public void add(java.lang.String name,
                java.lang.String value)
         throws java.lang.IllegalArgumentException
Add to or set a field. If the field is allowed to have multiple values, add will add multiple headers of the same name.

Parameters:
name - the name of the field
value - the value of the field.
Throws:
java.lang.IllegalArgumentException - If the name is a single valued field and already has a value.

remove

public java.lang.String remove(java.lang.String name)
Remove a field.

Parameters:
name -

getIntField

public int getIntField(java.lang.String name)
                throws java.lang.NumberFormatException
Get a header as an integer value. Returns the value of an integer field or -1 if not found. The case of the field name is ignored.

Parameters:
name - the case-insensitive field name
Throws:
java.lang.NumberFormatException - If bad integer found

getDateField

public long getDateField(java.lang.String name)
Get a header as a date value. Returns the value of a date field, or -1 if not found. The case of the field name is ignored.

Parameters:
name - the case-insensitive field name

putIntField

public void putIntField(java.lang.String name,
                        int value)
Sets the value of an integer field.

Parameters:
name - the field name
value - the field integer value

putDateField

public void putDateField(java.lang.String name,
                         java.util.Date date)
Sets the value of a date field.

Parameters:
name - the field name
date - the field date value

addDateField

public void addDateField(java.lang.String name,
                         java.util.Date date)
Adds the value of a date field.

Parameters:
name - the field name
date - the field date value

addDateField

public void addDateField(java.lang.String name,
                         long date)
Adds the value of a date field.

Parameters:
name - the field name
date - the field date value

putDateField

public void putDateField(java.lang.String name,
                         long date)
Sets the value of a date field.

Parameters:
name - the field name
date - the field date value

read

public void read(LineInput in)
          throws java.io.IOException
Read HttpHeaders from inputStream.

java.io.IOException

write

public void write(java.io.Writer writer)
           throws java.io.IOException
java.io.IOException

toString

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

clear

public void clear()
Clear the header.


destroy

public void destroy()
Destroy the header. Help the garbage collector by null everything that we can.


valueParameters

public static java.lang.String valueParameters(java.lang.String value,
                                               java.util.Map parameters)
Get field value parameters. Some field values can have parameters. This method separates the value from the parameters and optionally populates a map with the paramters. For example:
   FieldName : Value ; param1=val1 ; param2=val2
 

Parameters:
value - The Field value, possibly with parameteres.
parameters - A map to populate with the parameters, or null
Returns:
The value.

getQuality

public static java.lang.Float getQuality(java.lang.String value)

qualityList

public static java.util.List qualityList(java.util.Enumeration enum)
List values in quality order.

Parameters:
enum - Enumeration of values with quality parameters
Returns:
values in quality order.

addSetCookie

public void addSetCookie(Cookie cookie,
                         boolean cookie2)
Format a set cookie value

Parameters:
cookie - The cookie.
cookie2 - If true, use the alternate cookie 2 header

add

public void add(HttpFields fields)
Add fields from another HttpFields instance. Single valued fields are replaced, while all others are added.

Parameters:
fields -

iterator

public java.util.Iterator iterator()
return an iterator for field name:value pairs

Returns:
an HttpFields.Iterator


Copyright ? 2000 Mortbay Consulting Pty. Ltd. All Rights Reserved.