Class HttpStreamBase

  • All Implemented Interfaces:
    AutoCloseable
    Direct Known Subclasses:
    Http2Stream, HttpStream

    public class HttpStreamBase
    extends CrtResource
    An base class represents a single Http Request/Response for both HTTP/1.1 and HTTP/2 and wraps the native resources from the aws-c-http library. Can be used to update the Window size, or to abort the stream early in the middle of sending/receiving Http Bodies.
    • Method Detail

      • incrementWindow

        public void incrementWindow​(int windowSize)
        Increment the flow-control window, so that response data continues downloading.

        If HttpClientConnectionManagerOptions.withManualWindowManagement(boolean) was set true, each HTTP stream has a flow-control window that shrinks as response body data is downloaded (headers do not affect the size of the window). HttpClientConnectionManagerOptions.withWindowSize(long) sets the starting size for each HTTP stream's window. Whenever the window reaches zero, data stops downloading. Increment the window to keep data flowing. Maintain a larger window to keep up a high download throughput, parts cannot download in parallel unless the window is large enough to hold multiple parts. Maintain a smaller window to limit the amount of data buffered in memory.

        If manual window management is disabled this call has no effect.

        Parameters:
        windowSize - How many bytes to increment the sliding window by.
        See Also:
        HttpClientConnectionManagerOptions.withManualWindowManagement(boolean)
      • activate

        public void activate()
        Activates the client stream.
      • getResponseStatusCode

        public int getResponseStatusCode()
        Retrieves the Http Response Status Code
        Returns:
        The Http Response Status Code
      • cancel

        public void cancel()
        Cancels the stream with the default error code (AWS_ERROR_HTTP_STREAM_CANCELLED).

        For HTTP/1.1 streams, this is equivalent to closing the connection. For HTTP/2 streams, this sends a RST_STREAM frame with AWS_HTTP2_ERR_CANCEL.

        The stream will complete with AWS_ERROR_HTTP_STREAM_CANCELLED, unless the stream is already completing for other reasons, or the stream is not activated, in which case this call will have no effect.

      • writeData

        public void writeData​(byte[] data,
                              boolean endStream,
                              HttpStreamBase.HttpStreamWriteDataCompletionCallback completionCallback)
        Write data to an HTTP stream. Works for both HTTP/1.1 and HTTP/2. The stream must have been created with useManualDataWrites = true. You must call activate() before using this function.
        Parameters:
        data - data to send, or null to write zero bytes. Pass null with endStream=true to signal end-of-body without sending additional data.
        endStream - if true, this is the last data to be sent on this stream.
        completionCallback - invoked when the data has been flushed or an error occurs.
      • writeData

        public CompletableFuture<Void> writeData​(byte[] data,
                                                 boolean endStream)
        Write data to an HTTP stream. Works for both HTTP/1.1 and HTTP/2. The stream must have been created with useManualDataWrites = true. You must call activate() before using this function.
        Parameters:
        data - data to send, or null to write zero bytes. Pass null with endStream=true to signal end-of-body without sending additional data.
        endStream - if true, this is the last data to be sent on this stream.
        Returns:
        completable future which completes when data is flushed or an error occurs.