public class MessageHeader extends Object implements Message
Message
object is used to store an retrieve the
headers for both a request and response. Headers are stored and
retrieved in a case insensitive manner according to RFC 2616.
The message also allows multiple header values to be added to a
single header name, headers such as Cookie and Set-Cookie can be
added multiple times with different values.Constructor and Description |
---|
MessageHeader()
Constructor for the
Message object. |
Modifier and Type | Method and Description |
---|---|
void |
addDate(String name,
long date)
This is used as a convenience method for adding a header that
needs to be parsed into a HTTPdate string.
|
void |
addInteger(String name,
int value)
This can be used to add a HTTP message header to this object.
|
void |
addValue(String name,
String value)
This can be used to add a HTTP message header to this object.
|
List<String> |
getAll(String name)
This is used to acquire all the individual header values from
the message.
|
Cookie |
getCookie(String name)
This returns the
Cookie object stored under the
specified name. |
List<Cookie> |
getCookies()
This returns all
Cookie objects stored under the
specified name. |
long |
getDate(String name)
This can be used to get the value of the first message header
that has the specified name.
|
int |
getInteger(String name)
This can be used to get the value of the first message header
that has the specified name.
|
long |
getLong(String name)
This can be used to get the value of the first message header
that has the specified name.
|
List<String> |
getNames()
This is used to acquire the names of the of the headers that
have been set in the response.
|
String |
getValue(String name)
This can be used to get the value of the first message header
that has the specified name.
|
String |
getValue(String name,
int index)
This can be used to get the value of the first message header
that has the specified name.
|
List<String> |
getValues(List<String> list)
This can be used to get the values of HTTP message headers
that have the specified name.
|
List<String> |
getValues(String name)
This can be used to get the values of HTTP message headers
that have the specified name.
|
Cookie |
setCookie(Cookie cookie)
The
setCookie method is used to set a cookie value
with the cookie name. |
Cookie |
setCookie(String name,
String value)
The
setCookie method is used to set a cookie value
with the cookie name. |
void |
setDate(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 |
setInteger(String name,
int value)
This can be used to set a HTTP message header to this object.
|
void |
setLong(String name,
long value)
This can be used to set a HTTP message header to this object.
|
void |
setValue(String name,
String value)
This can be used to set a HTTP message header to this object.
|
public MessageHeader()
Message
object. This is used
to create a case insensitive means for storing HTTP header
names and values. Dates can also be added to message as a
long value and is converted to RFC 1123 compliant date string.public List<String> getNames()
public void setValue(String name, String value)
getValue
in combination with the get methods.
This will perform a remove
using the issued header
name before the header value is set.public void setInteger(String name, int value)
getValue
in combination with the get methods.
This will perform a remove
using the issued header
name before the header value is set.setInteger
in interface Message
name
- the name of the HTTP message header to be addedvalue
- the value the HTTP message header will havepublic void setLong(String name, long value)
getValue
in combination with the get methods.
This will perform a remove
using the issued header
name before the header value is set.name
- the name of the HTTP message header to be addedvalue
- the value the HTTP message header will havepublic void setDate(String name, long date)
remove
using the issued header
name before the header value is set.public void addValue(String name, String value)
getValue
in combination with the get methods.public void addInteger(String name, int value)
getInteger
in combination with the get methods.addInteger
in interface Message
name
- the name of the HTTP message header to be addedvalue
- the value the HTTP message header will havepublic void addDate(String name, long date)
public String getValue(String name)
public String getValue(String name, int index)
public int getInteger(String name)
getInteger
in interface Message
name
- the HTTP message header to get the value frompublic long getLong(String name)
name
- the HTTP message header to get the value frompublic long getDate(String name)
public Cookie getCookie(String name)
Cookie
object stored under the
specified name. This is used to retrieve cookies that have been
set with the setCookie
methods. If the cookie does
not exist under the specified name this will return null.public List<Cookie> getCookies()
Cookie
objects stored under the
specified name. This is used to retrieve cookies that have been
set with the setCookie
methods. If there are no
cookies then this will return an empty list.getCookies
in interface Message
Cookie
in the responsepublic Cookie setCookie(String name, String value)
setCookie
method is used to set a cookie value
with the cookie name. This will add a cookie to the response
stored under the name of the cookie, when this is committed it
will be added as a Set-Cookie header to the resulting response.
This is a convenience method that avoids cookie creation.public Cookie setCookie(Cookie cookie)
setCookie
method is used to set a cookie value
with the cookie name. This will add a cookie to the response
stored under the name of the cookie, when this is committed it
will be added as a Set-Cookie header to the resulting response.public List<String> getValues(String name)
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 appearance.
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 highest preference.
public List<String> getValues(List<String> list)
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 appearance.
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 highest preference.
Copyright © 2015. All rights reserved.