public static class HttpResponse.Builder extends Object
Constructor and Description |
---|
HttpResponse.Builder(ActorRef<? super WebMessage> from,
HttpRequest request) |
HttpResponse.Builder(ActorRef<? super WebMessage> from,
HttpRequest request,
ByteBuffer body) |
HttpResponse.Builder(ActorRef<? super WebMessage> from,
HttpRequest request,
String body) |
Modifier and Type | Method and Description |
---|---|
HttpResponse.Builder |
addCookie(Cookie cookie)
Adds the specified cookie to the response.
|
HttpResponse.Builder |
addHeader(String name,
String value)
Adds a response header with the given name and value.
|
HttpResponse |
build()
Instantiates a new immutable
HttpResponse based on the values set in this builder. |
HttpResponse.Builder |
error(Throwable error)
Associates an exception with an error status.
|
HttpResponse.Builder |
setCharacterEncoding(Charset charset)
Sets the character encoding (MIME charset) of the response being sent to the client, for example,
UTF-8 . |
HttpResponse.Builder |
setContentType(String contentType)
Sets the content type of the response being sent to the client.
|
HttpResponse.Builder |
startActor()
Indicates that the connection to the client must not be closed after sending this response; rather an
HttpStreamOpened message will be sent to the actor sending this response. |
HttpResponse.Builder |
status(int sc)
Sets the status code for this response.
|
public HttpResponse.Builder(ActorRef<? super WebMessage> from, HttpRequest request, String body)
public HttpResponse.Builder(ActorRef<? super WebMessage> from, HttpRequest request, ByteBuffer body)
public HttpResponse.Builder(ActorRef<? super WebMessage> from, HttpRequest request)
public HttpResponse.Builder setContentType(String contentType)
Sets the content type of the response being sent to the client.
The given content type may include a character encoding specification, for example,text/html;charset=UTF-8
. The Content-Type
header is used to communicate the content type and the character encoding used in the response writer to the clientcontentType
- the MIME type of the contentpublic HttpResponse.Builder setCharacterEncoding(Charset charset)
Sets the character encoding (MIME charset) of the response being sent to the client, for example, UTF-8
. If the character encoding has already been set by setContentType(java.lang.String)
, this method overrides it. Calling setContentType(java.lang.String)
with "text/html"
and calling this method with Charset.forName("UTF-8")
is equivalent with calling setContentType
with "text/html; charset=UTF-8"
.
charset
- only the character sets defined by IANA Character Sets (http://www.iana.org/assignments/character-sets)setContentType(java.lang.String)
public HttpResponse.Builder addHeader(String name, String value)
Adds a response header with the given name and value. This method allows response headers to have multiple values.
name
- the name of the headervalue
- the additional header value. If it contains octet string, it should be encoded according to RFC 2047 (http://www.ietf.org/rfc/rfc2047.txt)public HttpResponse.Builder addCookie(Cookie cookie)
Adds the specified cookie to the response. This method can be called multiple times to set multiple cookies.
cookie
- the Cookie
to return to the clientthis
public HttpResponse.Builder status(int sc)
Sets the status code for this response.
This method is used to set the return status code Valid status codes are those in the 2XX, 3XX, 4XX, and 5XX ranges. Other status codes are treated as container specific.
codes in the 4XX and 5XX range will be treated as error codes, and will trigger the container’s error reporting.
sc
- the status codethis
error
public HttpResponse.Builder error(Throwable error)
Associates an exception with an error status. The exception may be used in the error report which might be sent to the client.
error
- the exception responsible for the errorthis
public HttpResponse.Builder startActor()
Indicates that the connection to the client must not be closed after sending this response; rather an HttpStreamOpened
message will be sent to the actor sending this response.
this
public HttpResponse build()
Instantiates a new immutable HttpResponse
based on the values set in this builder.
HttpResponse