public interface ResponseHeader extends StatusLine
ResponseHeader
object is used to manipulate the
header information for a given response. Headers are stored and
retrieved from this object in a case insensitive manner. This
implements the StatusLine
object, which exposes the
protocol version and response status code.
All cookies set on the response header will be delivered as a Set-Cookie header in the response message. The Content-Length and Transfer-Encoding headers can be set to configure how the message body is delivered to the connected client.
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.
|
long |
getContentLength()
This is a convenience method that can be used to determine
the length of the message body.
|
ContentType |
getContentType()
This is a convenience method that can be used to determine the
content type of the message body.
|
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.
|
CharSequence |
getHeader()
This method returns a
CharSequence holding the header
created for the request. |
int |
getInteger(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 |
getTransferEncoding()
This is a convenience method that can be used to determine the
content type of the message body.
|
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(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.
|
String |
toString()
This method returns a string representing the header that was
generated for this header.
|
getCode, getDescription, getMajor, getMinor, getStatus, setCode, setDescription, setMajor, setMinor, setStatus
List<String> getNames()
void addValue(String name, String value)
getValue
in combination with the get methods.name
- the name of the HTTP message header to be addedvalue
- the value the HTTP message header will havevoid addInteger(String name, int value)
getInteger
in combination with the get methods.name
- the name of the HTTP message header to be addedvalue
- the value the HTTP message header will havevoid addDate(String name, long date)
name
- the name of the HTTP message header to be addeddate
- the value constructed as an RFC 1123 date stringvoid 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.name
- the name of the HTTP message header to be addedvalue
- the value the HTTP message header will havevoid 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.name
- the name of the HTTP message header to be addedvalue
- the value the HTTP message header will havevoid 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 havevoid setDate(String name, long date)
remove
using the issued header
name before the header value is set.name
- the name of the HTTP message header to be addeddate
- the value constructed as an RFC 1123 date stringString getValue(String name)
name
- the HTTP message header to get the value fromString getValue(String name, int index)
name
- the HTTP message header to get the value fromindex
- used if there are multiple headers presentint getInteger(String name)
name
- the HTTP message header to get the value fromlong getDate(String name)
name
- the HTTP message header to get the value fromList<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.
name
- the name of the headers that are to be retrievedCookie 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.cookie
- this is the cookie to be added to the responseCookie 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.name
- this is the cookie to be added to the responsevalue
- this is the cookie value that is to be usedCookie 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.name
- this is the name of the cookie to be retrievedCookie
by the given nameList<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.Cookie
in the responseContentType getContentType()
Content-Type
header, if there is then
this will parse that header and represent it as a typed object
which will expose the various parts of the HTTP header.String getTransferEncoding()
Transfer-Encoding
header, if there is
then this will parse that header and return the first token in
the comma separated list of values, which is the primary value.long getContentLength()
Content-Length
header, if it does then the
length can be determined, if not then this returns -1.CharSequence getHeader()
CharSequence
holding the header
created for the request. A character sequence is returned as it
can provide a much more efficient means of representing the header
data by just wrapping the the data generated.String toString()
Copyright © 2015. All rights reserved.