public class StandardResponse extends java.lang.Object implements HttpResponse
SC_ACCEPTED, SC_BAD_GATEWAY, SC_BAD_REQUEST, SC_CONFLICT, SC_CONTINUE, SC_CREATED, SC_EXPECTATION_FAILED, SC_FORBIDDEN, SC_FOUND, SC_GATEWAY_TIMEOUT, SC_GONE, SC_HTTP_VERSION_NOT_SUPPORTED, SC_INTERNAL_SERVER_ERROR, SC_LENGTH_REQUIRED, SC_METHOD_NOT_ALLOWED, SC_MOVED_PERMANENTLY, SC_MULTIPLE_CHOICES, SC_NO_CONTENT, SC_NON_AUTHORITATIVE_INFORMATION, SC_NOT_ACCEPTABLE, SC_NOT_FOUND, SC_NOT_IMPLEMENTED, SC_NOT_MODIFIED, SC_OK, SC_PARTIAL_CONTENT, SC_PAYMENT_REQUIRED, SC_PRECONDITION_FAILED, SC_PROXY_AUTHENTICATION_REQUIRED, SC_REQUEST_ENTITY_TOO_LARGE, SC_REQUEST_TIMEOUT, SC_REQUEST_URI_TOO_LONG, SC_REQUESTED_RANGE_NOT_SATISFIABLE, SC_RESET_CONTENT, SC_SEE_OTHER, SC_SERVICE_UNAVAILABLE, SC_SWITCHING_PROTOCOLS, SC_TEMPORARY_REDIRECT, SC_UNAUTHORIZED, SC_UNSUPPORTED_MEDIA_TYPE, SC_USE_PROXYACCEPT, ACCEPT_CHARSET, ACCEPT_ENCODING, ACCEPT_LANGUAGE, ACCEPT_RANGES, Access_Control_Allow_Credentials, Access_Control_Allow_Headers, Access_Control_Allow_Methods, Access_Control_Allow_Origin, Access_Control_Expose_Headers, Access_Control_Max_Age, Access_Control_Request_Headers, Access_Control_Request_Method, AGE, ALLOW, AUTHORIZATION, CACHE_CONTROL, CONNECTION, CONTENT_ENCODING, CONTENT_LANGUAGE, CONTENT_LENGTH, CONTENT_LOCATION, CONTENT_MD5, CONTENT_RANGE, CONTENT_TYPE, COOKIE, DATE, DAV, DEPTH, DESTINATION, ETAG, EXPECT, EXPIRES, FROM, HOST, IF, IF_MATCH, IF_MODIFIED_SINCE, IF_NONE_MATCH, IF_RANGE, IF_UNMODIFIED_SINCE, LAST_MODIFIED, LOCATION, LOCK_TOKEN, MAX_FORWARDS, ORIGIN, OVERWRITE, PRAGMA, PROXY_AUTHENTICATE, PROXY_AUTHORIZATION, RANGE, REFERER, RETRY_AFTER, SERVER, SET_COOKIE, STATUS_URI, TE, TIMEOUT, TRAILER, TRANSFER_ENCODING, UPGRADE, USER_AGENT, VARY, VIA, WARNING, WWW_AUTHENTICATE| Constructor and Description |
|---|
StandardResponse(org.apache.httpcore.HttpResponse response) |
| Modifier and Type | Method and Description |
|---|---|
void |
addCookie(Cookie cookie)
Adds the specified cookie to the response.
|
void |
addDateHeader(java.lang.String name,
long date)
Adds a response header with the given name and date-value.
|
void |
addHeader(java.lang.String name,
java.lang.String value)
Adds a response header with the given name and value.
|
void |
addIntHeader(java.lang.String name,
int value)
Adds a response header with the given name and integer value.
|
boolean |
containsHeader(java.lang.String name)
Returns a boolean indicating whether the named response header has already been set.
|
java.lang.String |
getHeader(java.lang.String name)
Gets the value of the response header with the given name.
|
java.util.List<java.lang.String> |
getHeaderNames()
Gets the names of the headers of this response.
|
java.util.List<java.lang.String> |
getHeaders(java.lang.String name)
Gets the values of the response header with the given name.
|
int |
getStatus()
Gets the current status code of this response.
|
void |
sendRedirect(java.lang.String location)
Sends a temporary redirect response to the client using the specified redirect location URL and clears the buffer.
|
void |
setBody(ResponseBody body)
Set the response body.
|
void |
setDateHeader(java.lang.String name,
long date)
Sets a response header with the given name and date-value.
|
void |
setHeader(java.lang.String name,
java.lang.String value)
Sets a response header with the given name and value.
|
void |
setIntHeader(java.lang.String name,
int value)
Sets a response header with the given name and integer value.
|
void |
setStatus(int sc)
Sets the status code for this response.
|
public StandardResponse(org.apache.httpcore.HttpResponse response)
public void setStatus(int sc)
HttpResponseThis method preserves any cookies and other response headers.
Valid status codes are those in the 2XX, 3XX, 4XX, and 5XX ranges. Other status codes will be considered to be specific.
setStatus in interface HttpResponsepublic int getStatus()
HttpResponsegetStatus in interface HttpResponsepublic void setHeader(java.lang.String name,
java.lang.String value)
HttpResponseHttpResponse.containsHeader(String) method can be used to test for the presence of a header before
setting its value.setHeader in interface HttpResponseHttpResponse.containsHeader(String),
HttpResponse.addHeader(String, String)public void addHeader(java.lang.String name,
java.lang.String value)
HttpResponseaddHeader in interface HttpResponseHttpResponse.setHeader(String, String)public java.lang.String getHeader(java.lang.String name)
HttpResponseIf a response header with the given name exists and contains multiple values, the value that was added first will be returned.
getHeader in interface HttpResponsename - the name of the response header.null if no header with the given name has
been set on this response.public void setDateHeader(java.lang.String name,
long date)
HttpResponseIf the header had already been set, the new value overwrites the previous one. The HttpResponse.containsHeader(String) method can be used to test for the presence of a header before setting its value.
setDateHeader in interface HttpResponseHttpResponse.containsHeader(String),
HttpResponse.addDateHeader(String, long)public void addDateHeader(java.lang.String name,
long date)
HttpResponseaddDateHeader in interface HttpResponseHttpResponse.setDateHeader(String, long)public void setIntHeader(java.lang.String name,
int value)
HttpResponseHttpResponse.containsHeader(String) method can be used to test for the presence of a
header before setting its value.setIntHeader in interface HttpResponseHttpResponse.containsHeader(String),
HttpResponse.addIntHeader(String, int)public void addIntHeader(java.lang.String name,
int value)
HttpResponseaddIntHeader in interface HttpResponseHttpResponse.setIntHeader(String, int)public boolean containsHeader(java.lang.String name)
HttpResponsecontainsHeader in interface HttpResponsepublic java.util.List<java.lang.String> getHeaders(java.lang.String name)
HttpResponsegetHeaders in interface HttpResponsename - the name of the response header.List of the values of the response header with the given name.public java.util.List<java.lang.String> getHeaderNames()
HttpResponsegetHeaderNames in interface HttpResponseEnumeration of the names of the headers of this response.public void addCookie(Cookie cookie)
HttpResponseaddCookie in interface HttpResponsecookie - the cookie to return to the client.public void sendRedirect(java.lang.String location)
HttpResponseStatusCode.SC_FOUND.sendRedirect in interface HttpResponsepublic void setBody(ResponseBody body)
HttpResponsesetBody in interface HttpResponsebody - write the message content sent to the client.