Class HttpChannelState.ChannelResponse

java.lang.Object
org.eclipse.jetty.server.internal.HttpChannelState.ChannelResponse
All Implemented Interfaces:
Content.Sink, Response, Callback, Invocable
Enclosing class:
HttpChannelState

public static class HttpChannelState.ChannelResponse extends Object implements Response, Callback
  • Field Details

    • _status

      protected int _status
  • Method Details

    • getResponseHttpFields

      protected ResponseHttpFields getResponseHttpFields(HttpChannelState httpChannelState)
    • getResponseHttpFields

      protected ResponseHttpFields getResponseHttpFields()
    • getContentBytesWritten

      public long getContentBytesWritten()
    • getRequest

      public Request getRequest()
      Specified by:
      getRequest in interface Response
      Returns:
      the Request associated with this Response
    • getStatus

      public int getStatus()
      Specified by:
      getStatus in interface Response
      Returns:
      the response HTTP status code
    • setStatus

      public void setStatus(int code)
      Description copied from interface: Response
      Set the response HTTP status code.
      Specified by:
      setStatus in interface Response
      Parameters:
      code - the response HTTP status code
    • getHeaders

      public HttpFields.Mutable getHeaders()
      Specified by:
      getHeaders in interface Response
      Returns:
      the response HTTP headers
    • getTrailersSupplier

      public Supplier<HttpFields> getTrailersSupplier()
      Specified by:
      getTrailersSupplier in interface Response
      Returns:
      a supplier for the HTTP trailers
    • setTrailersSupplier

      public void setTrailersSupplier(Supplier<HttpFields> trailers)
      Description copied from interface: Response

      Sets the supplier for the HTTP trailers.

      The method Supplier.get() may be called by the implementation multiple times, so it is important that the same value is returned in every invocation.

      Example:

      
       // Correct usage.
       HttpFields.Mutable trailers = HttpFields.build();
       response.setTrailersSupplier(() -> trailers);
      
       // WRONG usage, as the value changes for
       // every invocation of supplier.get().
       response.setTrailersSupplier(() -> HttpFields.build());
       
      Specified by:
      setTrailersSupplier in interface Response
      Parameters:
      trailers - a supplier for the HTTP trailers
    • write

      public void write(boolean last, ByteBuffer content, Callback callback)
      Description copied from interface: Response

      Writes the given ByteBuffer, notifying the Callback when the write is complete.

      Implementations guarantee that calls to this method are safely reentrant so that stack overflows are avoided in the case of mutual recursion between the execution of the Callback and a call to this method.

      The invocation of the passed Callback is serialized with previous calls of this method, so that it is not invoked until any invocation of the callback of a previous call to this method has returned.

      Thus a Callback should not block waiting for a callback of a future call to this method.

      Specified by:
      write in interface Content.Sink
      Specified by:
      write in interface Response
      Parameters:
      last - whether the ByteBuffer is the last to write
      content - the ByteBuffer to write
      callback - the callback to notify when the write operation is complete
    • succeeded

      public void succeeded()
      Called when the call to HttpStream.send(MetaData.Request, MetaData.Response, boolean, ByteBuffer, Callback) made by write(boolean, ByteBuffer, Callback) succeeds. The implementation maintains the HttpChannelState._streamSendState before taking and serializing the call to the _writeCallback, which was set by the call to write.
      Specified by:
      succeeded in interface Callback
      See Also:
    • failed

      public void failed(Throwable x)
      Called when the call to HttpStream.send(MetaData.Request, MetaData.Response, boolean, ByteBuffer, Callback) made by write(boolean, ByteBuffer, Callback) fails.

      The implementation maintains the HttpChannelState._streamSendState before taking and serializing the call to the _writeCallback, which was set by the call to write.

      Specified by:
      failed in interface Callback
      Parameters:
      x - The reason for the failure.
    • getInvocationType

      public Invocable.InvocationType getInvocationType()
      Specified by:
      getInvocationType in interface Invocable
      Returns:
      The InvocationType of this object
    • isCommitted

      public boolean isCommitted()
      Description copied from interface: Response

      Returns whether this response has already been committed.

      Committing a response means that the HTTP status code and HTTP headers cannot be modified anymore, typically because they have already been serialized and sent over the network.

      Specified by:
      isCommitted in interface Response
      Returns:
      whether this response has already been committed
    • hasLastWrite

      public boolean hasLastWrite()
      Description copied from interface: Response

      Returns whether the last write has been initiated on the response.

      Specified by:
      hasLastWrite in interface Response
      Returns:
      true if last==true has been passed to Response.write(boolean, ByteBuffer, Callback).
    • isCompletedSuccessfully

      public boolean isCompletedSuccessfully()
      Description copied from interface: Response

      Returns whether the response completed successfully.

      The response HTTP status code, HTTP headers and content have been successfully serialized and sent over the network without errors.

      Specified by:
      isCompletedSuccessfully in interface Response
      Returns:
      whether the response completed successfully
    • reset

      public void reset()
      Description copied from interface: Response

      Resets this response, clearing the HTTP status code, HTTP headers and HTTP trailers.

      Specified by:
      reset in interface Response
    • writeInterim

      public CompletableFuture<Void> writeInterim(int status, HttpFields headers)
      Description copied from interface: Response

      Writes an HTTP interim response, with the given HTTP status code and HTTP headers.

      It is possible to write more than one interim response, for example in case of HttpStatus.EARLY_HINTS_103.

      The returned CompletableFuture is notified of the result of this write, whether it succeeded or failed.

      Specified by:
      writeInterim in interface Response
      Parameters:
      status - the interim HTTP status code
      headers - the HTTP headers
      Returns:
      a CompletableFuture with the result of the write
    • toString

      public String toString()
      Overrides:
      toString in class Object