Interface ResponseHeader
-
- All Superinterfaces:
StatusLine
- All Known Subinterfaces:
Response
- All Known Implementing Classes:
ResponseEntity
,ResponseMessage
,ResponseWrapper
public interface ResponseHeader extends StatusLine
TheResponseHeader
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 theStatusLine
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.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
addDate(java.lang.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(java.lang.String name, int value)
This can be used to add a HTTP message header to this object.void
addValue(java.lang.String name, java.lang.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(java.lang.String name)
This returns theCookie
object stored under the specified name.java.util.List<Cookie>
getCookies()
This returns allCookie
objects stored under the specified name.long
getDate(java.lang.String name)
This can be used to get the value of the first message header that has the specified name.java.lang.CharSequence
getHeader()
This method returns aCharSequence
holding the header created for the request.int
getInteger(java.lang.String name)
This can be used to get the value of the first message header that has the specified name.java.util.List<java.lang.String>
getNames()
This is used to acquire the names of the of the headers that have been set in the response.java.lang.String
getTransferEncoding()
This is a convenience method that can be used to determine the content type of the message body.java.lang.String
getValue(java.lang.String name)
This can be used to get the value of the first message header that has the specified name.java.lang.String
getValue(java.lang.String name, int index)
This can be used to get the value of the first message header that has the specified name.java.util.List<java.lang.String>
getValues(java.lang.String name)
This can be used to get the values of HTTP message headers that have the specified name.Cookie
setCookie(java.lang.String name, java.lang.String value)
ThesetCookie
method is used to set a cookie value with the cookie name.Cookie
setCookie(Cookie cookie)
ThesetCookie
method is used to set a cookie value with the cookie name.void
setDate(java.lang.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(java.lang.String name, int value)
This can be used to set a HTTP message header to this object.void
setLong(java.lang.String name, long value)
This can be used to set a HTTP message header to this object.void
setValue(java.lang.String name, java.lang.String value)
This can be used to set a HTTP message header to this object.java.lang.String
toString()
This method returns a string representing the header that was generated for this header.-
Methods inherited from interface org.simpleframework.http.StatusLine
getCode, getDescription, getMajor, getMinor, getStatus, setCode, setDescription, setMajor, setMinor, setStatus
-
-
-
-
Method Detail
-
getNames
java.util.List<java.lang.String> getNames()
This is used to acquire the names of the of the headers that have been set in the response. This can be used to acquire all header values by name that have been set within the response. If no headers have been set this will return an empty list.- Returns:
- a list of strings representing the set header names
-
addValue
void addValue(java.lang.String name, java.lang.String value)
This can be used to add a HTTP message header to this object. The name and value of the HTTP message header will be used to create a HTTP message header object which can be retrieved using thegetValue
in combination with the get methods.- Parameters:
name
- the name of the HTTP message header to be addedvalue
- the value the HTTP message header will have
-
addInteger
void addInteger(java.lang.String name, int value)
This can be used to add a HTTP message header to this object. The name and value of the HTTP message header will be used to create a HTTP message header object which can be retrieved using thegetInteger
in combination with the get methods.- Parameters:
name
- the name of the HTTP message header to be addedvalue
- the value the HTTP message header will have
-
addDate
void addDate(java.lang.String name, long date)
This is used as a convenience method for adding a header that needs to be parsed into a HTTPdate string. This will convert the date given into a date string defined in RFC 2616 sec 3.3.1.- Parameters:
name
- the name of the HTTP message header to be addeddate
- the value constructed as an RFC 1123 date string
-
setValue
void setValue(java.lang.String name, java.lang.String value)
This can be used to set a HTTP message header to this object. The name and value of the HTTP message header will be used to create a HTTP message header object which can be retrieved using thegetValue
in combination with the get methods. This will perform aremove
using the issued header name before the header value is set.- Parameters:
name
- the name of the HTTP message header to be addedvalue
- the value the HTTP message header will have
-
setInteger
void setInteger(java.lang.String name, int value)
This can be used to set a HTTP message header to this object. The name and value of the HTTP message header will be used to create a HTTP message header object which can be retrieved using thegetValue
in combination with the get methods. This will perform aremove
using the issued header name before the header value is set.- Parameters:
name
- the name of the HTTP message header to be addedvalue
- the value the HTTP message header will have
-
setLong
void setLong(java.lang.String name, long value)
This can be used to set a HTTP message header to this object. The name and value of the HTTP message header will be used to create a HTTP message header object which can be retrieved using thegetValue
in combination with the get methods. This will perform aremove
using the issued header name before the header value is set.- Parameters:
name
- the name of the HTTP message header to be addedvalue
- the value the HTTP message header will have
-
setDate
void setDate(java.lang.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. This will convert the date given into a date string defined in RFC 2616 sec 3.3.1. This will perform aremove
using the issued header name before the header value is set.- Parameters:
name
- the name of the HTTP message header to be addeddate
- the value constructed as an RFC 1123 date string
-
getValue
java.lang.String getValue(java.lang.String name)
This can be used to get the value of the first message header that has the specified name. This will return the full string representing the named header value. If the named header does not exist then this will return a null value.- Parameters:
name
- the HTTP message header to get the value from- Returns:
- this returns the value that the HTTP message header
-
getValue
java.lang.String getValue(java.lang.String name, int index)
This can be used to get the value of the first message header that has the specified name. This will return the full string representing the named header value. If the named header does not exist then this will return a null value.- Parameters:
name
- the HTTP message header to get the value fromindex
- used if there are multiple headers present- Returns:
- this returns the value that the HTTP message header
-
getInteger
int getInteger(java.lang.String name)
This can be used to get the value of the first message header that has the specified name. This will return the integer representing the named header value. If the named header does not exist then this will return a value of minus one, -1.- Parameters:
name
- the HTTP message header to get the value from- Returns:
- this returns the value that the HTTP message header
-
getDate
long getDate(java.lang.String name)
This can be used to get the value of the first message header that has the specified name. This will return the long value representing the named header value. If the named header does not exist then this will return a value of minus one, -1.- Parameters:
name
- the HTTP message header to get the value from- Returns:
- this returns the value that the HTTP message header
-
getValues
java.util.List<java.lang.String> getValues(java.lang.String name)
This can be used to get the values of HTTP message headers that have the specified name. This is a convenience method that will present that values as tokens extracted from the header. This has obvious performance benefits as it avoids having to deal withsubstring
andtrim
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.
- Parameters:
name
- the name of the headers that are to be retrieved- Returns:
- ordered list of tokens extracted from the header(s)
-
setCookie
Cookie setCookie(Cookie cookie)
ThesetCookie
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.- Parameters:
cookie
- this is the cookie to be added to the response- Returns:
- returns the cookie that has been set in the response
-
setCookie
Cookie setCookie(java.lang.String name, java.lang.String value)
ThesetCookie
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.- Parameters:
name
- this is the cookie to be added to the responsevalue
- this is the cookie value that is to be used- Returns:
- returns the cookie that has been set in the response
-
getCookie
Cookie getCookie(java.lang.String name)
This returns theCookie
object stored under the specified name. This is used to retrieve cookies that have been set with thesetCookie
methods. If the cookie does not exist under the specified name this will return null.- Parameters:
name
- this is the name of the cookie to be retrieved- Returns:
- returns the
Cookie
by the given name
-
getCookies
java.util.List<Cookie> getCookies()
This returns allCookie
objects stored under the specified name. This is used to retrieve cookies that have been set with thesetCookie
methods. If there are no cookies then this will return an empty list.- Returns:
- returns all the
Cookie
in the response
-
getContentType
ContentType getContentType()
This is a convenience method that can be used to determine the content type of the message body. This will determine whether there is aContent-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.- Returns:
- this returns the content type value if it exists
-
getTransferEncoding
java.lang.String getTransferEncoding()
This is a convenience method that can be used to determine the content type of the message body. This will determine whether there is aTransfer-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.- Returns:
- this returns the transfer encoding value if it exists
-
getContentLength
long getContentLength()
This is a convenience method that can be used to determine the length of the message body. This will determine if there is aContent-Length
header, if it does then the length can be determined, if not then this returns -1.- Returns:
- content length, or -1 if it cannot be determined
-
getHeader
java.lang.CharSequence getHeader()
This method returns aCharSequence
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.- Returns:
- this returns the characters generated for the header
-
toString
java.lang.String toString()
This method returns a string representing the header that was generated for this header. For performance reasons it is better to acquire the character sequence representing the header as it does not require the allocation on new memory.- Overrides:
toString
in classjava.lang.Object
- Returns:
- this returns a string representation of this response
-
-