Package com.mastfrog.acteur
Class Response
java.lang.Object
com.mastfrog.acteur.Response
Abstraction for a response
- Author:
- Tim Boudreau
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract <T> Responseadd(HeaderValueType<T> headerType, T value) Add a header<T> ResponseaddIfUnset(HeaderValueType<T> headerType, T value) final Responsechunked()Set this response to be chunked.abstract Responsechunked(boolean chunked) Set chunked encoding - if set to true, the headers will indicate that chunked encoding will be used and noContent-Lengthheader will be sent.abstract ResponseSet a simple string messageabstract ResponsecontentWriter(ResponseWriter writer) Set a ResponseWriter which will be called after headers are written and flushed to the socket; this will cause chunked encoding to be used; the ResponseWriter will be called back repeatedly to stream more of the response until it says that it is done.abstract ResponsecontentWriter(io.netty.channel.ChannelFutureListener listener) Set a ChannelFutureListener which will be called after headers are written and flushed to the socket; prefersetResponseWriter()to this method unless you are not using chunked encoding and want to stream your response (in which case, be sure to chunked(false) or you will have encoding errors).abstract ResponseSet a delay before the response body should be sent; this is used for cases such as authentication where failed requests should be throttled.protected abstract <T> Tget(HeaderValueType<T> header) Get a header which has been previously setfinal ResponsesetBodyWriter(ResponseWriter writer) Deprecated.use contentWriter() insteadfinal ResponsesetBodyWriter(io.netty.channel.ChannelFutureListener listener) Deprecated.use contentWriter() insteadfinal ResponsesetChunked(boolean chunked) Deprecated.use chunked() insteadfinal ResponseDeprecated.use delayedBy() insteadfinal ResponsesetMessage(Object message) Deprecated.use content() insteadfinal ResponsesetResponseCode(io.netty.handler.codec.http.HttpResponseStatus status) Deprecated.use status() insteadabstract Responsestatus(io.netty.handler.codec.http.HttpResponseStatus status) Set the response codefinal ResponseSet this response not to use HTTP chunked encoding.
-
Constructor Details
-
Response
public Response()
-
-
Method Details
-
add
Add a header- Type Parameters:
T- The value type for the header- Parameters:
headerType- The header typevalue- The header value- Returns:
- this
-
addIfUnset
-
content
Set a simple string message- Parameters:
message- A message- Returns:
- this
-
status
Set the response code- Parameters:
status- The status- Returns:
- this
-
contentWriter
Set a ChannelFutureListener which will be called after headers are written and flushed to the socket; prefersetResponseWriter()to this method unless you are not using chunked encoding and want to stream your response (in which case, be sure to chunked(false) or you will have encoding errors).- Parameters:
listener- A ChannelFutureListener which will handle writing the response body after the headers are sent
-
contentWriter
Set a ResponseWriter which will be called after headers are written and flushed to the socket; this will cause chunked encoding to be used; the ResponseWriter will be called back repeatedly to stream more of the response until it says that it is done.- Parameters:
writer- A response writer instance which will handle writing the response body after the headers are sent- Returns:
- this
-
chunked
Set chunked encoding - if set to true, the headers will indicate that chunked encoding will be used and noContent-Lengthheader will be sent. Chunked encoding will also be defaulted to true if you callcontentWriter(ResponseWriter).- Parameters:
chunked-- Returns:
- this
-
delayedBy
Set a delay before the response body should be sent; this is used for cases such as authentication where failed requests should be throttled. This does mean the request will be held in memory until the delay is expired, so it may mean temporary increases in memory requirements.- Parameters:
delay- The delay- Returns:
- this
-
get
Get a header which has been previously set- Type Parameters:
T- The type- Parameters:
header- The header definition- Returns:
- The header value as type T
-
setMessage
Deprecated.use content() insteadSet a simple string message- Parameters:
message- A message- Returns:
- this
-
setResponseCode
@Deprecated public final Response setResponseCode(io.netty.handler.codec.http.HttpResponseStatus status) Deprecated.use status() insteadSet the response code- Parameters:
status- The status- Returns:
- this
-
setBodyWriter
Deprecated.use contentWriter() insteadSet a ChannelFutureListener which will be called after headers are written and flushed to the socket; prefersetResponseWriter()to this method unless you are not using chunked encoding and want to stream your response (in which case, be sure to setChunked(false) or you will have encoding errors).- Parameters:
listener- A ChannelFutureListener which will handle writing the response body after the headers are sent
-
setBodyWriter
Deprecated.use contentWriter() insteadSet a ResponseWriter which will be called after headers are written and flushed to the socket; this will cause chunked encoding to be used; the ResponseWriter will be called back repeatedly to stream more of the response until it says that it is done.- Parameters:
writer- A response writer instance which will handle writing the response body after the headers are sent- Returns:
- this
-
setChunked
Deprecated.use chunked() insteadSet chunked encoding - if set to true, the headers will indicate that chunked encoding will be used and noContent-Lengthheader will be sent. Chunked encoding will also be defaulted to true if you callsetBodyWriter(ResponseWriter).- Parameters:
chunked-- Returns:
- this
-
setDelay
Deprecated.use delayedBy() insteadSet a delay before the response body should be sent; this is used for cases such as authentication where failed requests should be throttled. This does mean the request will be held in memory until the delay is expired, so it may mean temporary increases in memory requirements.- Parameters:
delay- The delay- Returns:
- this
-
chunked
Set this response to be chunked.- Returns:
- this
-
unchunked
Set this response not to use HTTP chunked encoding.- Returns:
- this
-