Interface HttpTransport

All Superinterfaces:
AutoCloseable, Closeable
All Known Implementing Classes:
ApacheHc45Transport, ApacheHc5Transport, JavaHttpTransport, JettyHttpTransport, MockHttpTransport, OkHttpTransport

public interface HttpTransport extends Closeable
SPI for pluggable HTTP transports.

An HttpTransport is responsible for executing a fully-resolved TransportRequest and returning a TransportResponse. Implementations include:

  • ApacheHc45Transport (module juneau-rest-client-apache-httpclient-45)
  • ApacheHc5Transport (module juneau-rest-client-apache-httpclient-50)
  • JavaHttpTransport (module juneau-rest-client-java-httpclient)
  • OkHttpTransport (module juneau-rest-client-okhttp)
  • JettyHttpTransport (module juneau-rest-client-jetty)
  • MockHttpTransport (module juneau-rest-mock)

Implementations are discovered automatically via HttpTransportProvider using ServiceLoader, or set explicitly via RestClient.Builder#transport(HttpTransport).

See Also:
Since:
9.2.1
  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    Releases resources held by this transport (connection pools, threads, etc.).
    Executes the given request and returns the response.
    default boolean
    Returns true if this transport can honor the SSRF guardrail's connect-time contract for a policy-covered request (TransportRequest.isSsrfGuardActive()): pin-on-connect to a resolved address that has passed the deny-private policy, and Juneau-controlled redirect revalidation (no fallback to the transport's own auto-follow).
  • Method Details

    • execute

      Executes the given request and returns the response.

      The caller is responsible for closing the returned TransportResponse after consuming the body.

      Parameters:
      request - The fully-resolved request. Must not be null.
      Returns:
      The response. Never null.
      Throws:
      TransportException - If a network-level error occurs.
    • supportsUrlPolicy

      default boolean supportsUrlPolicy()
      Returns true if this transport can honor the SSRF guardrail's connect-time contract for a policy-covered request (TransportRequest.isSsrfGuardActive()): pin-on-connect to a resolved address that has passed the deny-private policy, and Juneau-controlled redirect revalidation (no fallback to the transport's own auto-follow).

      The default implementation returns false (fail closed): an unknown/caller-supplied transport that has not affirmatively opted in is presumed unable to honor the contract, so RestRequest#run() rejects policy-covered requests against it rather than silently connecting without the guardrail. First-party transports that construct and fully control their own underlying HTTP client override this to return true.

      Returns:
      true if this transport supports pin-on-connect + redirect revalidation for policy-covered requests.
    • close

      default void close() throws IOException
      Releases resources held by this transport (connection pools, threads, etc.).

      The default implementation is a no-op.

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException