Class Response

java.lang.Object
com.mastfrog.acteur.Response

public abstract class Response extends Object
Abstraction for a response
Author:
Tim Boudreau
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract <T> Response
    add(HeaderValueType<T> headerType, T value)
    Add a header
    addIfUnset(HeaderValueType<T> headerType, T value)
     
    final Response
    Set this response to be chunked.
    abstract Response
    chunked(boolean chunked)
    Set chunked encoding - if set to true, the headers will indicate that chunked encoding will be used and no Content-Length header will be sent.
    abstract Response
    content(Object message)
    Set a simple string message
    abstract Response
    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 Response
    contentWriter(io.netty.channel.ChannelFutureListener listener)
    Set a ChannelFutureListener which will be called after headers are written and flushed to the socket; prefer setResponseWriter() 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 Response
    Set 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> T
    get(HeaderValueType<T> header)
    Get a header which has been previously set
    final Response
    Deprecated.
    use contentWriter() instead
    final Response
    setBodyWriter(io.netty.channel.ChannelFutureListener listener)
    Deprecated.
    use contentWriter() instead
    final Response
    setChunked(boolean chunked)
    Deprecated.
    use chunked() instead
    final Response
    Deprecated.
    use delayedBy() instead
    final Response
    setMessage(Object message)
    Deprecated.
    use content() instead
    final Response
    setResponseCode(io.netty.handler.codec.http.HttpResponseStatus status)
    Deprecated.
    use status() instead
    abstract Response
    status(io.netty.handler.codec.http.HttpResponseStatus status)
    Set the response code
    final Response
    Set this response not to use HTTP chunked encoding.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Response

      public Response()
  • Method Details

    • add

      public abstract <T> Response add(HeaderValueType<T> headerType, T value)
      Add a header
      Type Parameters:
      T - The value type for the header
      Parameters:
      headerType - The header type
      value - The header value
      Returns:
      this
    • addIfUnset

      public <T> Response addIfUnset(HeaderValueType<T> headerType, T value)
    • content

      public abstract Response content(Object message)
      Set a simple string message
      Parameters:
      message - A message
      Returns:
      this
    • status

      public abstract Response status(io.netty.handler.codec.http.HttpResponseStatus status)
      Set the response code
      Parameters:
      status - The status
      Returns:
      this
    • contentWriter

      public abstract Response contentWriter(io.netty.channel.ChannelFutureListener listener)
      Set a ChannelFutureListener which will be called after headers are written and flushed to the socket; prefer setResponseWriter() 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

      public abstract Response contentWriter(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.
      Parameters:
      writer - A response writer instance which will handle writing the response body after the headers are sent
      Returns:
      this
    • chunked

      public abstract Response chunked(boolean chunked)
      Set chunked encoding - if set to true, the headers will indicate that chunked encoding will be used and no Content-Length header will be sent. Chunked encoding will also be defaulted to true if you call contentWriter(ResponseWriter).
      Parameters:
      chunked -
      Returns:
      this
    • delayedBy

      public abstract Response delayedBy(Duration delay)
      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

      protected abstract <T> T get(HeaderValueType<T> header)
      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 public final Response setMessage(Object message)
      Deprecated.
      use content() instead
      Set 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() instead
      Set the response code
      Parameters:
      status - The status
      Returns:
      this
    • setBodyWriter

      @Deprecated public final Response setBodyWriter(io.netty.channel.ChannelFutureListener listener)
      Deprecated.
      use contentWriter() instead
      Set a ChannelFutureListener which will be called after headers are written and flushed to the socket; prefer setResponseWriter() 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

      public final Response setBodyWriter(ResponseWriter writer)
      Deprecated.
      use contentWriter() instead
      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
    • setChunked

      @Deprecated public final Response setChunked(boolean chunked)
      Deprecated.
      use chunked() instead
      Set chunked encoding - if set to true, the headers will indicate that chunked encoding will be used and no Content-Length header will be sent. Chunked encoding will also be defaulted to true if you call setBodyWriter(ResponseWriter).
      Parameters:
      chunked -
      Returns:
      this
    • setDelay

      @Deprecated public final Response setDelay(Duration delay)
      Deprecated.
      use delayedBy() instead
      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
    • chunked

      public final Response chunked()
      Set this response to be chunked.
      Returns:
      this
    • unchunked

      public final Response unchunked()
      Set this response not to use HTTP chunked encoding.
      Returns:
      this