Class OkHttpTransportBuilder

java.lang.Object
org.apache.juneau.rest.client.okhttp.OkHttpTransportBuilder

public final class OkHttpTransportBuilder extends Object
Fluent builder for OkHttpTransport.

Obtain an instance via OkHttpTransport.builder().

See Also:
Since:
9.2.1
  • Method Details

    • httpClient

      public OkHttpTransportBuilder httpClient(okhttp3.OkHttpClient value)
      Sets the underlying OkHttpClient to use.

      If not set, a default client is created via new OkHttpClient().

      A client with an explicit proxy makes OkHttpTransport.supportsUrlPolicy() report false (the proxy resolves the target host itself, bypassing the SSRF guard's address pinning), so RestRequest refuses to send an SSRF-guard-active request through it. A client whose ProxySelector routes a guarded request through a proxy is refused at send time.

      The transport sends through a client derived from this one with OkHttpClient.newBuilder() (it shares the connection pool, dispatcher and settings), adding a network interceptor that strips caller-set credential headers (Authorization, Cookie and the rest of RedirectSecurity.stripOnCrossOrigin()) when OkHttp follows a redirect to a different origin. The client passed in is not modified.

      Once a hop has been stripped, later hops of the same call stay stripped, including one back to the first origin. That state travels on a tag of the request, so a network interceptor or an Authenticator on the client that builds a request from scratch (rather than from request.newBuilder()) must preserve the request's tags, or the sticky strip is lost.

      OkHttp recommends sharing a single OkHttpClient instance across the application. When sharing, the caller is responsible for lifecycle management; OkHttpTransport.close() will still attempt to drain the client's connection pool and executor.

      Parameters:
      value - The client to use. Must not be null.
      Returns:
      This object.
    • build

      Builds and returns the OkHttpTransport.
      Returns:
      A new instance. Never null.