org.mortbay.http

Class HttpFields

public class HttpFields extends 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.77 2006/11/22 20:02:15 gregwilkins Exp $

Author: Greg Wilkins (gregw)

Nested Class Summary
classHttpFields.Entry
Field Summary
static String__01Jan1970
static String__Accept
Request Fields.
static String__AcceptCharset
Request Fields.
static String__AcceptEncoding
Request Fields.
static String__AcceptLanguage
Request Fields.
static String__AcceptRanges
Response Fields.
static String__Age
Response Fields.
static String__Allow
Entity Fields.
static String__Authorization
Request Fields.
static String__CacheControl
General Fields.
static String__Chunked
Fields Values.
static String__Close
static String__Connection
General Fields.
static String__ContentEncoding
Entity Fields.
static String__ContentLanguage
Entity Fields.
static String__ContentLength
Entity Fields.
static String__ContentLocation
Entity Fields.
static String__ContentMD5
Entity Fields.
static String__ContentRange
Entity Fields.
static String__ContentType
Entity Fields.
static String__Cookie
Other Fields.
static char[]__COLON
static char[]__CRLF
static DateCache__dateCache
static ThreadLocal__dateReceiveCache
static SimpleDateFormat[]__dateReceiveSource
static String__Date
General Fields.
static String__ETag
Response Fields.
static String__Expect
Request Fields.
static String__ExpectContinue
static String__Expires
Entity Fields.
static String__Forwarded
Request Fields.
static String__From
Request Fields.
static String__Host
Request Fields.
static String__Identity
Other Fields.
static String__IfMatch
Request Fields.
static String__IfModifiedSince
Request Fields.
static String__IfNoneMatch
Request Fields.
static String__IfRange
Request Fields.
static String__IfUnmodifiedSince
Request Fields.
static String__KeepAlive
Request Fields.
static String__LastModified
Entity Fields.
static String__Location
Response Fields.
static String__MaxForwards
Request Fields.
static String__MessageHttp
static String__MimeVersion
Other Fields.
static String__Pragma
General Fields.
static String__ProxyAuthenticate
Response Fields.
static String__ProxyAuthorization
Request Fields.
static String__ProxyConnection
General Fields.
static String__Range
Request Fields.
static String__Referer
Request Fields.
static String__RequestRange
Request Fields.
static String__RetryAfter
Response Fields.
static String__separators
static String__Server
Response Fields.
static String__ServletEngine
Response Fields.
static String__SetCookie
Other Fields.
static String__SetCookie2
Other Fields.
static String__SoapAction
Other Fields.
static String__TextHtml
static String__TE
Request Fields.
static String__Trailer
General Fields.
static String__TransferEncoding
General Fields.
static String__Upgrade
General Fields.
static String__UserAgent
Request Fields.
static String__Vary
Response Fields.
static String__Via
General Fields.
static String__Warning
General Fields.
static String__WwwAuthenticate
Response Fields.
static String__WwwFormUrlEncode
static String__XForwardedFor
Request Fields.
Constructor Summary
HttpFields()
Constructor.
Method Summary
voidadd(String name, String value)
Add to or set a field.
voidadd(HttpFields fields)
Add fields from another HttpFields instance.
voidaddDateField(String name, Date date)
Adds the value of a date field.
voidaddDateField(String name, long date)
Adds the value of a date field.
voidaddSetCookie(Cookie cookie)
Format a set cookie value
voidclear()
Clear the header.
booleancontainsKey(String name)
voiddestroy()
Destroy the header.
static StringformatDate(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 StringformatDate(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 StringformatDate(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
static voidformatDate(StringBuffer buf, 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
Stringget(String name)
longgetDateField(String name)
Get a header as a date value.
EnumerationgetFieldNames()
Get enumeration of header _names.
intgetIntField(String name)
Get a header as an integer value.
static FloatgetQuality(String value)
EnumerationgetValues(String name)
Get multi headers
EnumerationgetValues(String name, String separators)
Get multi field values with separator.
Iteratoriterator()
return an iterator for field name:value pairs
Stringput(String name, String value)
Set a field.
voidput(String name, List list)
Set a field.
voidputDateField(String name, Date date)
Sets the value of a date field.
voidputDateField(String name, long date)
Sets the value of a date field.
voidputIntField(String name, int value)
Sets the value of an integer field.
static ListqualityList(Enumeration enm)
List values in quality order.
voidread(LineInput in)
Read HttpHeaders from inputStream.
Stringremove(String name)
Remove a field.
intsize()
StringtoString()
static StringvalueParameters(String value, Map parameters)
Get field value parameters.
voidwrite(Writer writer)

Field Detail

__01Jan1970

public static final String __01Jan1970

__Accept

public static final String __Accept
Request Fields.

__AcceptCharset

public static final String __AcceptCharset
Request Fields.

__AcceptEncoding

public static final String __AcceptEncoding
Request Fields.

__AcceptLanguage

public static final String __AcceptLanguage
Request Fields.

__AcceptRanges

public static final String __AcceptRanges
Response Fields.

__Age

public static final String __Age
Response Fields.

__Allow

public static final String __Allow
Entity Fields.

__Authorization

public static final String __Authorization
Request Fields.

__CacheControl

public static final String __CacheControl
General Fields.

__Chunked

public static final String __Chunked
Fields Values.

__Close

public static final String __Close

__Connection

public static final String __Connection
General Fields.

__ContentEncoding

public static final String __ContentEncoding
Entity Fields.

__ContentLanguage

public static final String __ContentLanguage
Entity Fields.

__ContentLength

public static final String __ContentLength
Entity Fields.

__ContentLocation

public static final String __ContentLocation
Entity Fields.

__ContentMD5

public static final String __ContentMD5
Entity Fields.

__ContentRange

public static final String __ContentRange
Entity Fields.

__ContentType

public static final String __ContentType
Entity Fields.

__Cookie

public static final String __Cookie
Other Fields.

__COLON

public static final char[] __COLON

__CRLF

public static final char[] __CRLF

__dateCache

public static final DateCache __dateCache

__dateReceiveCache

public static final ThreadLocal __dateReceiveCache

__dateReceiveSource

public static SimpleDateFormat[] __dateReceiveSource

__Date

public static final String __Date
General Fields.

__ETag

public static final String __ETag
Response Fields.

__Expect

public static final String __Expect
Request Fields.

__ExpectContinue

public static final String __ExpectContinue

__Expires

public static final String __Expires
Entity Fields.

__Forwarded

public static final String __Forwarded
Request Fields.

__From

public static final String __From
Request Fields.

__Host

public static final String __Host
Request Fields.

__Identity

public static final String __Identity
Other Fields.

__IfMatch

public static final String __IfMatch
Request Fields.

__IfModifiedSince

public static final String __IfModifiedSince
Request Fields.

__IfNoneMatch

public static final String __IfNoneMatch
Request Fields.

__IfRange

public static final String __IfRange
Request Fields.

__IfUnmodifiedSince

public static final String __IfUnmodifiedSince
Request Fields.

__KeepAlive

public static final String __KeepAlive
Request Fields.

__LastModified

public static final String __LastModified
Entity Fields.

__Location

public static final String __Location
Response Fields.

__MaxForwards

public static final String __MaxForwards
Request Fields.

__MessageHttp

public static final String __MessageHttp

__MimeVersion

public static final String __MimeVersion
Other Fields.

__Pragma

public static final String __Pragma
General Fields.

__ProxyAuthenticate

public static final String __ProxyAuthenticate
Response Fields.

__ProxyAuthorization

public static final String __ProxyAuthorization
Request Fields.

__ProxyConnection

public static final String __ProxyConnection
General Fields.

__Range

public static final String __Range
Request Fields.

__Referer

public static final String __Referer
Request Fields.

__RequestRange

public static final String __RequestRange
Request Fields.

__RetryAfter

public static final String __RetryAfter
Response Fields.

__separators

public static final String __separators

__Server

public static final String __Server
Response Fields.

__ServletEngine

public static final String __ServletEngine
Response Fields.

__SetCookie

public static final String __SetCookie
Other Fields.

__SetCookie2

public static final String __SetCookie2
Other Fields.

__SoapAction

public static final String __SoapAction
Other Fields.

__TextHtml

public static final String __TextHtml

__TE

public static final String __TE
Request Fields.

__Trailer

public static final String __Trailer
General Fields.

__TransferEncoding

public static final String __TransferEncoding
General Fields.

__Upgrade

public static final String __Upgrade
General Fields.

__UserAgent

public static final String __UserAgent
Request Fields.

__Vary

public static final String __Vary
Response Fields.

__Via

public static final String __Via
General Fields.

__Warning

public static final String __Warning
General Fields.

__WwwAuthenticate

public static final String __WwwAuthenticate
Response Fields.

__WwwFormUrlEncode

public static final String __WwwFormUrlEncode

__XForwardedFor

public static final String __XForwardedFor
Request Fields.

Constructor Detail

HttpFields

public HttpFields()
Constructor.

Method Detail

add

public void add(String name, String value)
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: IllegalArgumentException If the name is a single valued field and already has a value.

add

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

Parameters: fields

addDateField

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

Parameters: name the field name date the field date value

addDateField

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

Parameters: name the field name date the field date value

addSetCookie

public void addSetCookie(Cookie cookie)
Format a set cookie value

Parameters: cookie The cookie.

clear

public void clear()
Clear the header.

containsKey

public boolean containsKey(String name)

destroy

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

formatDate

public static 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 String formatDate(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 String formatDate(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(StringBuffer buf, 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

get

public String get(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.

getDateField

public long getDateField(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

getFieldNames

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

getIntField

public int getIntField(String name)
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: NumberFormatException If bad integer found

getQuality

public static Float getQuality(String value)

getValues

public Enumeration getValues(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 Enumeration getValues(String name, 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.

iterator

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

Returns: an HttpFields.Iterator

put

public String put(String name, 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(String name, 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.

putDateField

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

Parameters: name the field name date the field date value

putDateField

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

Parameters: name the field name date the field date value

putIntField

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

Parameters: name the field name value the field integer value

qualityList

public static List qualityList(Enumeration enm)
List values in quality order.

Parameters: enm Enumeration of values with quality parameters

Returns: values in quality order.

read

public void read(LineInput in)
Read HttpHeaders from inputStream.

remove

public String remove(String name)
Remove a field.

Parameters: name

size

public int size()

toString

public String toString()

valueParameters

public static String valueParameters(String value, 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.

write

public void write(Writer writer)
Copyright © 2004 Mortbay Consulting Pty. Ltd. All Rights Reserved.