Interface ResponseBodyControl

  • All Known Implementing Classes:
    NettyResponseBodyControl

    public interface ResponseBodyControl
    Controls transport reads for a response body.

    The control is thread-safe and remains valid until its response completes. Calls made after completion have no effect.

    A control is also supplied when the final response headers end the response without a body. In that case, suspend() cannot defer completion: the control becomes inactive when AsyncHandler.onResponseBodyStart(ResponseBodyControl) returns, and later calls have no effect.

    Since:
    3.0.14
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void cancel()
      Stops processing the response body.
      void resume()
      Resumes requesting response bytes after a call to suspend().
      void suspend()
      Stops requesting additional response bytes from the transport.
    • Method Detail

      • suspend

        void suspend()
        Stops requesting additional response bytes from the transport. Body parts that were already read may still be delivered to the AsyncHandler. If the final response headers already ended the response, this call has no effect on completion.

        While reads are suspended, the read timeout is paused but the request timeout remains active. If the request timeout is disabled, failing to resume or cancel the response can retain its transport resources indefinitely.

        For HTTP/2, while any response on a connection is suspended, AHC continues returning connection-level flow-control credit so a suspended stream cannot block sibling streams. Responses on connections with no active suspension retain the normal shared connection-window bound. The per-stream window always applies, so roughly AsyncHttpClientConfig.getHttp2InitialWindowSize() bytes can be queued for each suspended stream. Aggregate buffering during suspension can therefore scale with the number of concurrent streams. Once the last suspension ends, normal connection accounting resumes; credit already returned and data already queued cannot be revoked. Applications can bound buffering with AsyncHttpClientConfig.getHttp2InitialWindowSize() and AsyncHttpClientConfig.getHttp2MaxConcurrentStreams().

      • resume

        void resume()
        Resumes requesting response bytes after a call to suspend().
      • cancel

        void cancel()
        Stops processing the response body. As with AsyncHandler.State.ABORT, the handler is completed normally. Returning ABORT is the preferred way to stop from within an AsyncHandler callback; this method is intended for cancellation after the callback has returned, including from another thread.