public abstract class HttpResponse extends HttpMessage
An HTTP response message sent as a response to an HttpRequest. When this response is sent to an HttpRequest’s sender, the connection stream will be closed if openChannel has not been called on the request, and will be flushed but not closed if openChannel has been called on the request.
| Modifier and Type | Class and Description |
|---|---|
static class |
HttpResponse.Builder |
| Constructor and Description |
|---|
HttpResponse() |
| Modifier and Type | Method and Description |
|---|---|
protected String |
contentString() |
static HttpResponse.Builder |
error(ActorRef<? super WebMessage> from,
HttpRequest request,
int status,
String body)
Creates an
HttpResponse indicating an error, with a given status code and a text body. |
static HttpResponse.Builder |
error(ActorRef<? super WebMessage> from,
HttpRequest request,
int status,
Throwable cause)
Creates an
HttpResponse indicating an error, with a given status code and an attached exception that may be reported back to the client. |
abstract Throwable |
getError()
An exception optionally associated with an error status code.
|
abstract ActorRef<WebMessage> |
getFrom()
The actor that sent this message.
|
abstract String |
getRedirectPath()
The redirect URL target if this is a
redirect response. |
abstract HttpRequest |
getRequest()
The
HttpRequest this is a response to. |
abstract int |
getStatus()
The response’s HTTP status code.
|
static HttpResponse.Builder |
ok(ActorRef<? super WebMessage> from,
HttpRequest request,
ByteBuffer body)
Creates an
HttpResponse with a binary body and response code 200. |
static HttpResponse.Builder |
ok(ActorRef<? super WebMessage> from,
HttpRequest request,
String body)
Creates an
HttpResponse with a text body and response code 200. |
static HttpResponse.Builder |
redirect(HttpRequest request,
String redirectPath)
Sends a temporary redirect response to the client using the specified redirect location URL and clears the buffer.
|
abstract boolean |
shouldStartActor() |
getCharacterEncoding, getContentLength, getContentType, getCookies, getHeader, getHeaders, getHeaderValuesgetByteBufferBody, getStringBodytoStringpublic abstract ActorRef<WebMessage> getFrom()
WebMessageThe actor that sent this message. This can be a virtual actor representing the web client.
getFrom in interface FromMessagegetFrom in class WebMessagepublic abstract HttpRequest getRequest()
The HttpRequest this is a response to.
public abstract int getStatus()
The response’s HTTP status code.
public abstract Throwable getError()
An exception optionally associated with an error status code.
public abstract String getRedirectPath()
The redirect URL target if this is a redirect response.
public abstract boolean shouldStartActor()
protected String contentString()
contentString in class WebMessagepublic static HttpResponse.Builder ok(ActorRef<? super WebMessage> from, HttpRequest request, String body)
Creates an HttpResponse with a text body and response code 200.
request - the HttpRequest this is a response to.body - the response bodyHttpResponse.Builder that can be used to add headers and other metadata to the response.public static HttpResponse.Builder ok(ActorRef<? super WebMessage> from, HttpRequest request, ByteBuffer body)
Creates an HttpResponse with a binary body and response code 200.
request - the HttpRequest this is a response to.body - the response bodyHttpResponse.Builder that can be used to add headers and other metadata to the response.public static HttpResponse.Builder error(ActorRef<? super WebMessage> from, HttpRequest request, int status, Throwable cause)
Creates an HttpResponse indicating an error, with a given status code and an attached exception that may be reported back to the client.
request - the HttpRequest this is a response to.status - the response status codecause - the exception that caused the errorHttpResponse.Builder that can be used to add headers and other metadata to the response.public static HttpResponse.Builder error(ActorRef<? super WebMessage> from, HttpRequest request, int status, String body)
Creates an HttpResponse indicating an error, with a given status code and a text body.
request - the HttpRequest this is a response to.status - the response status codebody - the response bodyHttpResponse.Builder that can be used to add headers and other metadata to the response.public static HttpResponse.Builder redirect(HttpRequest request, String redirectPath)
Sends a temporary redirect response to the client using the specified redirect location URL and clears the buffer. The status code is set to SC_FOUND 302 (Found). This method can accept relative URLs; the container must convert the relative URL to an absolute URL before sending the response to the client. If the location is relative without a leading ‘/’ the container interprets it as relative to the current request URI. If the location is relative with a leading ‘/’ the container interprets it as relative to the container root. If the location is relative with two leading ‘/’ the container interprets it as a network-path reference (see RFC 3986: Uniform Resource Identifier (URI): Generic Syntax, section 4.2 "Relative Reference").
redirectPath - the redirect location URL