Interface HTTPClientStream

All Superinterfaces:
AutoCloseable, Closeable, HTTPMessageStream
All Known Implementing Classes:
AbstractHTTPClientStream

public interface HTTPClientStream extends HTTPMessageStream
A HTTPClientStream represents a single HTTP request transaction from the perspective of the client, including the outgoing HTTPRequest and its data, and is used for receiving the corresponding response.
Since:
1.4.1
See Also:
  • Method Details

    • getClient

      HTTPClient getClient()
      Returns the HTTPClient that created this HTTPClientStream.
      Returns:
      The HTTPClient
    • startRequest

      void startRequest()
      Starts the request passed in a constructor.

      This method must be followed by at least one call to sendRequestData(byte[], boolean) or endRequest(HTTPMessageTrailers).

      Throws:
      IllegalStateException - If this method was called already (optional)
    • sendRequestData

      boolean sendRequestData(byte[] data, boolean lastPacket)
      Streams request data.
      Parameters:
      data - The data
      lastPacket - true if this is the last piece of data being sent
      Returns:
      true if the underlying connection is writable, false if the write buffer is full and data will have to be queued
      Throws:
      IllegalStateException - If the request has ended already (optional)
      See Also:
    • endRequest

      default void endRequest(HTTPMessageTrailers trailers)
      Ends this request, allowing the server to send the response. Optional trailers are sent with the request, if supported.
      Parameters:
      trailers - If not null, the trailers to send
    • onServerPush

      default void onServerPush(Consumer<HTTPClientStream> onServerPush)
      Sets a callback that is called when this HTTPClientStream receives a pushed request.

      This callback is always called before the onResponse callback. If the underlying protocol does not support server push, this callback is never called.

      The new HTTPClientStream passed to the callback is used to receive the pushed response. The methods startRequest(), sendRequestData(byte[], boolean), and endRequest(HTTPMessageTrailers) should not be called on this HTTPClientStream. The onResponse callback will be called as soon as the pushed response is received.

      Parameters:
      onServerPush - The callback
    • getResponse

      HTTPResponse getResponse()
      Returns the received response of this HTTPClientStream, or null if no response was received yet.
      Returns:
      The response
    • onResponse

      void onResponse(Consumer<HTTPResponse> onResponse)
      Sets a callback that is called when this HTTPClientStream receives a response.

      No other callbacks in this HTTPClientStream are called before the given callback has returned.

      This callback may be called multiple times when receiving multiple responses (for example, a 102 Processing followed by the actual response, see also: HTTPResponse.isIntermediateMessage()).

      Parameters:
      onResponse - The callback
    • onResponseData

      void onResponseData(Consumer<HTTPResponseData> onResponseData)
      Sets a callback that is called when this HTTPClientStream receives data for the response.

      If HTTPMessageData.isLastPacket() is true for a HTTPResponseData object passed to the callback, it is followed by a onResponseEnded callback.

      Parameters:
      onResponseData - The callback
    • onResponseEnded

      void onResponseEnded(Consumer<HTTPMessageTrailers> onResponseEnded)
      Sets a callback that is called when this HTTPClientStream has finished receiving the response and data, including optional trailers.

      If this callback is called, this HTTPClientStream is implicitly closed and no further callbacks will be called.

      Parameters:
      onResponseEnded - The callback