public class HttpFields extends Object implements Iterable<HttpField>
This class is not synchronised as it is expected that modifications will only be performed by a single thread.
The cookie handling provided by this class is guided by the Servlet specification and RFC6265.
Modifier and Type | Class and Description |
---|---|
static class |
HttpFields.DateGenerator |
Modifier and Type | Field and Description |
---|---|
static String |
__01Jan1970 |
static ByteBuffer |
__01Jan1970_BUFFER |
static String |
__01Jan1970_COOKIE |
static String |
__COOKIE_DELIM |
static DateCache |
__dateCache |
static TimeZone |
__GMT |
static String |
__separators |
Constructor and Description |
---|
HttpFields()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
add(HttpField field) |
void |
add(HttpFields fields)
Add fields from another HttpFields instance.
|
void |
add(HttpHeader header,
HttpHeaderValue value) |
void |
add(HttpHeader header,
String value)
Add to or set a field.
|
void |
add(String name,
String value)
Add to or set a field.
|
void |
addDateField(String name,
long date)
Sets the value of a date field.
|
void |
addSetCookie(HttpCookie cookie)
Format a set cookie value
|
void |
addSetCookie(String name,
String value,
String domain,
String path,
long maxAge,
String comment,
boolean isSecure,
boolean isHttpOnly,
int version)
Format a set cookie value
|
void |
clear()
Clear the header.
|
boolean |
contains(HttpHeader header,
String value) |
boolean |
contains(String name,
String value) |
boolean |
containsKey(String name) |
static String |
formatCookieDate(long date)
Format "EEE, dd-MMM-yyyy HH:mm:ss 'GMT'" for cookies
|
static void |
formatCookieDate(StringBuilder buf,
long date)
Format "EEE, dd-MMM-yyyy HH:mm:ss 'GMT'" for cookies
|
static String |
formatDate(long date)
Format HTTP date "EEE, dd MMM yyyy HH:mm:ss 'GMT'"
|
String |
get(HttpHeader header) |
String |
get(String header) |
long |
getDateField(String name)
Get a header as a date value.
|
HttpField |
getField(HttpHeader header) |
HttpField |
getField(int i)
Get a Field by index.
|
HttpField |
getField(String name) |
Enumeration<String> |
getFieldNames()
Get enumeration of header _names.
|
Collection<String> |
getFieldNamesCollection()
Get Collection of header names.
|
long |
getLongField(String name)
Get a header as an long value.
|
static Float |
getQuality(String value) |
String |
getStringField(HttpHeader header) |
String |
getStringField(String name) |
Enumeration<String> |
getValues(String name)
Get multi headers
|
Enumeration<String> |
getValues(String name,
String separators)
Get multi field values with separator.
|
Collection<String> |
getValuesCollection(String name)
Get multi headers
|
static boolean |
isQuoteNeededForCookie(String s)
Does a cookie value need to be quoted?
|
Iterator<HttpField> |
iterator() |
static long |
parseDate(String date) |
void |
put(HttpField field) |
void |
put(HttpHeader header,
HttpHeaderValue value) |
void |
put(HttpHeader header,
String value)
Set a field.
|
void |
put(String name,
List<String> list)
Set a field.
|
void |
put(String name,
String value)
Set a field.
|
void |
putDateField(HttpHeader name,
long date)
Sets the value of a date field.
|
void |
putDateField(String name,
long date)
Sets the value of a date field.
|
void |
putLongField(HttpHeader name,
long value)
Sets the value of an long field.
|
void |
putLongField(String name,
long value)
Sets the value of an long field.
|
void |
putTo(ByteBuffer bufferInFillMode) |
static List<String> |
qualityList(Enumeration<String> e)
List values in quality order.
|
void |
remove(HttpHeader name)
Remove a field.
|
void |
remove(String name)
Remove a field.
|
int |
size() |
String |
toString() |
static String |
valueParameters(String value,
Map<String,String> parameters)
Get field value parameters.
|
public static final TimeZone __GMT
public static final DateCache __dateCache
public static final String __COOKIE_DELIM
public static final String __separators
public static final String __01Jan1970
public static final ByteBuffer __01Jan1970_BUFFER
public static final String __01Jan1970_COOKIE
public static String formatDate(long date)
public static void formatCookieDate(StringBuilder buf, long date)
public static String formatCookieDate(long date)
public static long parseDate(String date)
public Collection<String> getFieldNamesCollection()
public Enumeration<String> getFieldNames()
public int size()
public HttpField getField(int i)
public HttpField getField(HttpHeader header)
public boolean contains(HttpHeader header, String value)
public boolean containsKey(String name)
public String getStringField(HttpHeader header)
public String get(HttpHeader header)
public String getStringField(String name)
name
- the case-insensitive field namepublic Collection<String> getValuesCollection(String name)
name
- the case-insensitive field namepublic Enumeration<String> getValues(String name)
name
- the case-insensitive field namepublic Enumeration<String> getValues(String name, String separators)
name
- the case-insensitive field nameseparators
- String of separators.public void put(HttpField field)
public void put(String name, String value)
name
- the name of the fieldvalue
- the value of the field. If null the field is cleared.public void put(HttpHeader header, HttpHeaderValue value)
public void put(HttpHeader header, String value)
header
- the header name of the fieldvalue
- the value of the field. If null the field is cleared.public void put(String name, List<String> list)
name
- the name of the fieldlist
- the List value of the field. If null the field is cleared.public void add(String name, String value) throws IllegalArgumentException
name
- the name of the fieldvalue
- the value of the field.IllegalArgumentException
- If the name is a single valued field and already has a
value.public void add(HttpHeader header, HttpHeaderValue value) throws IllegalArgumentException
IllegalArgumentException
public void add(HttpHeader header, String value) throws IllegalArgumentException
header
- the headervalue
- the value of the field.IllegalArgumentException
public void remove(HttpHeader name)
name
- the field to removepublic void remove(String name)
name
- the field to removepublic long getLongField(String name) throws NumberFormatException
name
- the case-insensitive field nameNumberFormatException
- If bad long foundpublic long getDateField(String name)
name
- the case-insensitive field namepublic void putLongField(HttpHeader name, long value)
name
- the field namevalue
- the field long valuepublic void putLongField(String name, long value)
name
- the field namevalue
- the field long valuepublic void putDateField(HttpHeader name, long date)
name
- the field namedate
- the field date valuepublic void putDateField(String name, long date)
name
- the field namedate
- the field date valuepublic void addDateField(String name, long date)
name
- the field namedate
- the field date valuepublic void addSetCookie(HttpCookie cookie)
cookie
- The cookie.public void addSetCookie(String name, String value, String domain, String path, long maxAge, String comment, boolean isSecure, boolean isHttpOnly, int version)
name
- the namevalue
- the valuedomain
- the domainpath
- the pathmaxAge
- the maximum agecomment
- the comment (only present on versions > 0)isSecure
- true if secure cookieisHttpOnly
- true if for http onlyversion
- version of cookie logic to use (0 == default behavior)public void putTo(ByteBuffer bufferInFillMode)
public void clear()
public void add(HttpField field)
public void add(HttpFields fields)
fields
- the fields to addpublic static String valueParameters(String value, Map<String,String> parameters)
FieldName : Value ; param1=val1 ; param2=val2
value
- The Field value, possibly with parameteres.parameters
- A map to populate with the parameters, or nullpublic static List<String> qualityList(Enumeration<String> e)
e
- Enumeration of values with quality parameterspublic static boolean isQuoteNeededForCookie(String s)
s
- value stringIllegalArgumentException
- If there a control characters in the stringCopyright © 1995-2013 Mort Bay Consulting. All Rights Reserved.