org.mortbay.http

Class 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.76 2005/08/13 00:01:24 gregwilkins Exp $
Author:
Greg Wilkins (gregw)

Nested Class Summary

class
HttpFields.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 char[]
__COLON
static char[]
__CRLF
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 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
__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
__TE
Request Fields.
static String
__TextHtml
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.
static DateCache
__dateCache
static ThreadLocal
__dateReceiveCache
static SimpleDateFormat[]
__dateReceiveSource
static String
__separators

Constructor Summary

HttpFields()
Constructor.

Method Summary

void
add(String name, String value)
Add to or set a field.
void
add(HttpFields fields)
Add fields from another HttpFields instance.
void
addDateField(String name, Date date)
Adds the value of a date field.
void
addDateField(String name, long date)
Adds the value of a date field.
void
addSetCookie(Cookie cookie)
Format a set cookie value
void
clear()
Clear the header.
boolean
containsKey(String name)
void
destroy()
Destroy the header.
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
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
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
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
String
get(String name)
long
getDateField(String name)
Get a header as a date value.
Enumeration
getFieldNames()
Get enumeration of header _names.
int
getIntField(String name)
Get a header as an integer value.
static Float
getQuality(String value)
Enumeration
getValues(String name)
Get multi headers
Enumeration
getValues(String name, String separators)
Get multi field values with separator.
Iterator
iterator()
return an iterator for field name:value pairs
void
put(String name, List list)
Set a field.
String
put(String name, String value)
Set a field.
void
putDateField(String name, Date date)
Sets the value of a date field.
void
putDateField(String name, long date)
Sets the value of a date field.
void
putIntField(String name, int value)
Sets the value of an integer field.
static List
qualityList(Enumeration enm)
List values in quality order.
void
read(LineInput in)
Read HttpHeaders from inputStream.
String
remove(String name)
Remove a field.
int
size()
String
toString()
static String
valueParameters(String value, Map parameters)
Get field value parameters.
void
write(Writer writer)

Field Details

__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.

__COLON

public static final char[] __COLON

__CRLF

public static final char[] __CRLF

__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.

__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.

__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.

__TE

public static final String __TE
Request Fields.

__TextHtml

public static final String __TextHtml

__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.

__dateCache

public static final DateCache __dateCache

__dateReceiveCache

public static final ThreadLocal __dateReceiveCache

__dateReceiveSource

public static SimpleDateFormat[] __dateReceiveSource

__separators

public static final String __separators

Constructor Details

HttpFields

public HttpFields()
Constructor.

Method Details

add

public void add(String name,
                String value)
            throws 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.

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(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 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

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 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

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)
            throws 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

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 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.

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.

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)
            throws IOException
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)
            throws IOException

Copyright © 2004 Mortbay Consulting Pty. Ltd. All Rights Reserved.