Builder

class Builder

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard
@JvmName(name = "-addInterceptor")
inline fun addInterceptor(crossinline block: (chain: Interceptor.Chain) -> Response): OkHttpClient.Builder
Link copied to clipboard
@JvmName(name = "-addNetworkInterceptor")
inline fun addNetworkInterceptor(crossinline block: (chain: Interceptor.Chain) -> Response): OkHttpClient.Builder
Link copied to clipboard

Sets the authenticator used to respond to challenges from origin servers. Use proxyAuthenticator to set the authenticator for proxy servers.

Link copied to clipboard
Link copied to clipboard

Sets the response cache to be used to read and write cached responses.

Link copied to clipboard
@IgnoreJRERequirement
fun callTimeout(duration: Duration): OkHttpClient.Builder

Sets the default timeout for complete calls. A value of 0 means no timeout, otherwise values must be between 1 and Integer.MAX_VALUE when converted to milliseconds.

Link copied to clipboard

Sets the certificate pinner that constrains which certificates are trusted. By default HTTPS connections rely on only the SSL socket factory to establish trust. Pinning certificates avoids the need to trust certificate authorities.

Link copied to clipboard

Sets the connection pool used to recycle HTTP and HTTPS connections.

Link copied to clipboard
Link copied to clipboard
@IgnoreJRERequirement
fun connectTimeout(duration: Duration): OkHttpClient.Builder

Sets the default connect timeout for new connections. A value of 0 means no timeout, otherwise values must be between 1 and Integer.MAX_VALUE when converted to milliseconds.

Link copied to clipboard

Sets the handler that can accept cookies from incoming HTTP responses and provides cookies to outgoing HTTP requests.

Link copied to clipboard

Sets the dispatcher used to set policy and execute asynchronous requests. Must not be null.

Link copied to clipboard

Sets the DNS service used to lookup IP addresses for hostnames.

Link copied to clipboard

Configure a single client scoped listener that will receive all analytic events for this client.

Link copied to clipboard

Configure a factory to provide per-call scoped listeners that will receive analytic events for this client.

Link copied to clipboard

Configure this client to perform fast fallbacks by attempting multiple connections concurrently, returning once any connection connects successfully.

Link copied to clipboard

Configure this client to follow redirects. If unset, redirects will be followed.

Link copied to clipboard
fun followSslRedirects(followProtocolRedirects: Boolean): OkHttpClient.Builder

Configure this client to allow protocol redirects from HTTPS to HTTP and from HTTP to HTTPS. Redirects are still first restricted by followRedirects. Defaults to true.

Link copied to clipboard

Sets the verifier used to confirm that response certificates apply to requested hostnames for HTTPS connections.

Link copied to clipboard

Returns a modifiable list of interceptors that observe the full span of each call: from before the connection is established (if any) until after the response source is selected (either the origin server, cache, or both).

Link copied to clipboard

Sets minimum outbound web socket message size (in bytes) that will be compressed.

Link copied to clipboard

Returns a modifiable list of interceptors that observe a single network request and response. These interceptors must call Interceptor.Chain.proceed exactly once: it is an error for a network interceptor to short-circuit or repeat a network request.

Link copied to clipboard
@IgnoreJRERequirement
fun pingInterval(duration: Duration): OkHttpClient.Builder

Sets the interval between HTTP/2 and web socket pings initiated by this client. Use this to automatically send ping frames until either the connection fails or it is closed. This keeps the connection alive and may detect connectivity failures.

Link copied to clipboard

Configure the protocols used by this client to communicate with remote servers. By default this client will prefer the most efficient transport available, falling back to more ubiquitous protocols. Applications should only call this method to avoid specific compatibility problems, such as web servers that behave incorrectly when HTTP/2 is enabled.

Link copied to clipboard

Sets the HTTP proxy that will be used by connections created by this client. This takes precedence over proxySelector, which is only honored when this proxy is null (which it is by default). To disable proxy use completely, call proxy(Proxy.NO_PROXY).

Link copied to clipboard

Sets the authenticator used to respond to challenges from proxy servers. Use authenticator to set the authenticator for origin servers.

Link copied to clipboard

Sets the proxy selection policy to be used if no proxy is specified explicitly. The proxy selector may return multiple proxies; in that case they will be tried in sequence until a successful connection is established.

Link copied to clipboard
@IgnoreJRERequirement
fun readTimeout(duration: Duration): OkHttpClient.Builder

Sets the default read timeout for new connections. A value of 0 means no timeout, otherwise values must be between 1 and Integer.MAX_VALUE when converted to milliseconds.

Link copied to clipboard
fun retryOnConnectionFailure(retryOnConnectionFailure: Boolean): OkHttpClient.Builder

Configure this client to retry or not when a connectivity problem is encountered. By default, this client silently recovers from the following problems:

Link copied to clipboard

Sets the socket factory used to create connections. OkHttp only uses the parameterless SocketFactory.createSocket method to create unconnected sockets. Overriding this method, e. g., allows the socket to be bound to a specific local address.

Link copied to clipboard

Sets the socket factory and trust manager used to secure HTTPS connections. If unset, the system defaults will be used.

Link copied to clipboard
@IgnoreJRERequirement
fun webSocketCloseTimeout(duration: Duration): OkHttpClient.Builder

Sets the close timeout for web socket connections. A value of 0 means no timeout, otherwise values must be between 1 and Integer.MAX_VALUE when converted to milliseconds.

Link copied to clipboard
@IgnoreJRERequirement
fun writeTimeout(duration: Duration): OkHttpClient.Builder

Sets the default write timeout for new connections. A value of 0 means no timeout, otherwise values must be between 1 and Integer.MAX_VALUE when converted to milliseconds.