Interface HttpTransport

All Known Implementing Classes:
DefaultHttpTransport

public interface HttpTransport
The HTTP service provider interface: one request in, one response out, no policy.

This is the type an application, a platform or a test implements to replace the SDK's HTTP stack — for a corporate proxy, mTLS, tracing, or to run on Android, where java.net.http does not exist at any API level.

An implementer must satisfy the following; everything not listed is free.

Ownership follows construction. A Client closes only a transport it built itself; an injected transport is never closed by the SDK, because it is almost always a wrapper over a process-wide client the application also uses.

  • Method Details

    • roundTrip

      CompletionStage<HttpResponse> roundTrip(HttpRequest request, Cancellation cancellation)
      Perform one exchange.

      Never throws: a failure completes the returned stage exceptionally with an HttpTransportException.

      Parameters:
      request - the request to perform
      cancellation - the caller's cancellation; Cancellation.none() when there is none. An implementation must release its registration when the exchange ends.
      Returns:
      a stage completing with the response, or exceptionally with an HttpTransportException
    • close

      void close(Duration closeTimeout)
      Release whatever this transport owns, within a bounded grace period.

      Not asynchronous, because every SDK's Client.close() is synchronous and making this one asynchronous would make that one asynchronous too.

      Parameters:
      closeTimeout - how long to wait for exchanges already in flight before cancelling them