Interface ServerResponse

All Known Subinterfaces:
RoutingResponse
All Known Implementing Classes:
ServerResponseBase

public interface ServerResponse
Http server response.
  • Method Details

    • status

      ServerResponse status(Status status)
      Status of the response.
      Parameters:
      status - HTTP status
      Returns:
      this instance
    • status

      default ServerResponse status(int status)
      Status of the response.
      Parameters:
      status - HTTP status as integer
      Returns:
      this instance
    • status

      Status status()
      Configured HTTP status, if not configured, returns Status.OK_200.
      Returns:
      status
    • header

      default ServerResponse header(HeaderName name, String... values)
      Set a header. If the values are constant, please use HeaderValues.create(io.helidon.http.HeaderName, String...) and store the header in a constant field and call header(io.helidon.http.Header).
      Parameters:
      name - header name
      values - value(s) of the header
      Returns:
      this instance
    • header

      default ServerResponse header(String name, String... values)
      Not optimized method for setting a header. Use for unknown headers, where HeaderName cannot be cached. Use header(io.helidon.http.Header) or header(HeaderName, String...) otherwise.
      Parameters:
      name - name of the header
      values - values of the header
      Returns:
      this instance
    • header

      ServerResponse header(Header header)
      Set header with a value. Headers cannot be set after outputStream() method is called, or after the response was sent.
      Parameters:
      header - header value
      Returns:
      this instance
      Throws:
      IllegalStateException - in case a header is set after output stream was requested, or the response was sent
      See Also:
    • send

      void send()
      Send a response with no entity.
    • send

      void send(byte[] bytes)
      Send a byte array response.
      Parameters:
      bytes - bytes to send
    • send

      default void send(byte[] bytes, int position, int length)
      Send a byte array response.
      Parameters:
      bytes - bytes to send
      position - starting position
      length - number of bytes send
    • send

      void send(Object entity)
      Send an entity, a MediaContext will be used to serialize the entity.
      Parameters:
      entity - entity object
    • send

      default void send(Optional<?> entity)
      Send an entity if present, throw NotFoundException if empty.
      Parameters:
      entity - entity as an optional
    • isSent

      boolean isSent()
      Whether this response has been sent.
      Returns:
      whether sent
    • outputStream

      OutputStream outputStream()
      Alternative way to send an entity, using an output stream. This should be used for entities that are big and that should not be materialized into memory.
      Returns:
      output stream
    • bytesWritten

      long bytesWritten()
      Number of bytes written to response. Only available once the response is sent.
      Returns:
      bytes written (combination of all bytes of status, headers and entity)
    • whenSent

      ServerResponse whenSent(Runnable listener)
      Completed when last byte is buffered for socket write.
      Parameters:
      listener - listener to add to list of listeners that will be triggered once response is sent
      Returns:
      this instance
    • reroute

      ServerResponse reroute(String newPath)
      Re-route using a different path.
      Parameters:
      newPath - new path to use
      Returns:
      this instance
    • reroute

      ServerResponse reroute(String path, UriQuery query)
      Re-route using a different path and query.
      Parameters:
      path - new path
      query - new query
      Returns:
      this instance
      Throws:
      IllegalStateException - in case the entity was already configured
      See Also:
    • next

      Continue processing with the next route (and if none found, return a Status.NOT_FOUND_404). If any entity method was called, this method will throw an exception.
      Returns:
      this instance
      Throws:
      IllegalStateException - in case the entity was already configured
    • headers

      Response headers (mutable).
      Returns:
      headers
    • trailers

      Response trailers (mutable).
      Returns:
      trailers
      Throws:
      IllegalStateException - if client didn't ask for trailers with TE: trailers header in request or response doesn't contain trailer declaration headers Trailer: <trailer-name>
    • streamResult

      void streamResult(String result)
      Description of the result of output stream processing. In case an output stream was used, calling this method will immediately close the stream and return this message as the reason for closing the response. In HTTP/1 this would be in a trailer header
      Parameters:
      result - result description
    • contentLength

      default void contentLength(long length)
      Configure a content length header for this response.
      Parameters:
      length - content length
    • sink

      default <T extends Sink<?>> T sink(GenericType<T> sinkType)
      Returns a sink from this response based on the sink type, if available.
      Type Parameters:
      T - type of sink returned
      Parameters:
      sinkType - type of sink
      Returns:
      sink or null if not available
    • streamFilter

      void streamFilter(UnaryOperator<OutputStream> filterFunction)
      Configure a custom output stream to wrap the output stream of the response.
      Parameters:
      filterFunction - the function to replace output stream of this response with a user provided one