//okhttp/okhttp3/OkHttpClient/Builder
Builder¶
[jvm]\ class Builder
Constructors¶
Builder | [jvm] fun Builder() |
Functions¶
Name | Summary |
---|---|
addInterceptor | [jvm] @JvmName(name = "-addInterceptor") inline fun addInterceptor(crossinline block: (chain: Interceptor.Chain) -> Response): OkHttpClient.Builder fun addInterceptor(interceptor: Interceptor): OkHttpClient.Builder |
addNetworkInterceptor | [jvm] @JvmName(name = "-addNetworkInterceptor") inline fun addNetworkInterceptor(crossinline block: (chain: Interceptor.Chain) -> Response): OkHttpClient.Builder fun addNetworkInterceptor(interceptor: Interceptor): OkHttpClient.Builder |
authenticator | [jvm] fun authenticator(authenticator: Authenticator): OkHttpClient.Builder Sets the authenticator used to respond to challenges from origin servers. Use proxyAuthenticator to set the authenticator for proxy servers. |
build | [jvm] fun build(): OkHttpClient |
cache | [jvm] fun cache(cache: Cache?): OkHttpClient.Builder Sets the response cache to be used to read and write cached responses. |
callTimeout | [jvm] @IgnoreJRERequirement fun callTimeout(duration: Duration): OkHttpClient.Builder fun callTimeout(timeout: Long, unit: TimeUnit): 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. |
certificatePinner | [jvm] fun certificatePinner(certificatePinner: CertificatePinner): OkHttpClient.Builder 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. |
connectionPool | [jvm] fun connectionPool(connectionPool: ConnectionPool): OkHttpClient.Builder Sets the connection pool used to recycle HTTP and HTTPS connections. |
connectionSpecs | [jvm] fun connectionSpecs(connectionSpecs: List<ConnectionSpec>): OkHttpClient.Builder |
connectTimeout | [jvm] @IgnoreJRERequirement fun connectTimeout(duration: Duration): OkHttpClient.Builder fun connectTimeout(timeout: Long, unit: TimeUnit): 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. |
cookieJar | [jvm] fun cookieJar(cookieJar: CookieJar): OkHttpClient.Builder Sets the handler that can accept cookies from incoming HTTP responses and provides cookies to outgoing HTTP requests. |
dispatcher | [jvm] fun dispatcher(dispatcher: Dispatcher): OkHttpClient.Builder Sets the dispatcher used to set policy and execute asynchronous requests. Must not be null. |
dns | [jvm] fun dns(dns: Dns): OkHttpClient.Builder Sets the DNS service used to lookup IP addresses for hostnames. |
eventListener | [jvm] fun eventListener(eventListener: EventListener): OkHttpClient.Builder Configure a single client scoped listener that will receive all analytic events for this client. |
eventListenerFactory | [jvm] fun eventListenerFactory(eventListenerFactory: EventListener.Factory): OkHttpClient.Builder Configure a factory to provide per-call scoped listeners that will receive analytic events for this client. |
fastFallback | [jvm] fun fastFallback(fastFallback: Boolean): OkHttpClient.Builder Configure this client to perform fast fallbacks by attempting multiple connections concurrently, returning once any connection connects successfully. |
followRedirects | [jvm] fun followRedirects(followRedirects: Boolean): OkHttpClient.Builder Configure this client to follow redirects. If unset, redirects will be followed. |
followSslRedirects | [jvm] 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. |
hostnameVerifier | [jvm] fun hostnameVerifier(hostnameVerifier: HostnameVerifier): OkHttpClient.Builder Sets the verifier used to confirm that response certificates apply to requested hostnames for HTTPS connections. |
interceptors | [jvm] fun interceptors(): MutableList<Interceptor> 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). |
minWebSocketMessageToCompress | [jvm] fun minWebSocketMessageToCompress(bytes: Long): OkHttpClient.Builder Sets minimum outbound web socket message size (in bytes) that will be compressed. |
networkInterceptors | [jvm] fun networkInterceptors(): MutableList<Interceptor> 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. |
pingInterval | [jvm] @IgnoreJRERequirement fun pingInterval(duration: Duration): OkHttpClient.Builder fun pingInterval(interval: Long, unit: TimeUnit): 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. |
protocols | [jvm] fun protocols(protocols: List<Protocol>): OkHttpClient.Builder 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. |
proxy | [jvm] fun proxy(proxy: Proxy?): OkHttpClient.Builder 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) . |
proxyAuthenticator | [jvm] fun proxyAuthenticator(proxyAuthenticator: Authenticator): OkHttpClient.Builder Sets the authenticator used to respond to challenges from proxy servers. Use authenticator to set the authenticator for origin servers. |
proxySelector | [jvm] fun proxySelector(proxySelector: ProxySelector): OkHttpClient.Builder 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. |
readTimeout | [jvm] @IgnoreJRERequirement fun readTimeout(duration: Duration): OkHttpClient.Builder fun readTimeout(timeout: Long, unit: TimeUnit): 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. |
retryOnConnectionFailure | [jvm] 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: |
socketFactory | [jvm] fun socketFactory(socketFactory: SocketFactory): OkHttpClient.Builder 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. |
sslSocketFactory | [jvm] fun sslSocketFactory(sslSocketFactory: SSLSocketFactory, trustManager: X509TrustManager): OkHttpClient.Builder Sets the socket factory and trust manager used to secure HTTPS connections. If unset, the system defaults will be used. |
writeTimeout | [jvm] @IgnoreJRERequirement fun writeTimeout(duration: Duration): OkHttpClient.Builder fun writeTimeout(timeout: Long, unit: TimeUnit): 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. |