Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,7 @@ class TestValueFactory : Closeable {
index = 0,
exchange = null,
request = call.request(),
connectTimeoutMillis = 10_000,
readTimeoutMillis = 10_000,
writeTimeoutMillis = 10_000,
client = call.client,
)

fun newRoutePlanner(
Expand Down
30 changes: 30 additions & 0 deletions okhttp/api/android/okhttp.api
Original file line number Diff line number Diff line change
Expand Up @@ -749,12 +749,42 @@ public abstract interface class okhttp3/Interceptor$Chain {
public abstract fun call ()Lokhttp3/Call;
public abstract fun connectTimeoutMillis ()I
public abstract fun connection ()Lokhttp3/Connection;
public abstract fun getAuthenticator ()Lokhttp3/Authenticator;
public abstract fun getCache ()Lokhttp3/Cache;
public abstract fun getCertificateChainCleaner ()Lokhttp3/internal/tls/CertificateChainCleaner;
public abstract fun getCertificatePinner ()Lokhttp3/CertificatePinner;
public abstract fun getConnectionPool ()Lokhttp3/ConnectionPool;
public abstract fun getCookieJar ()Lokhttp3/CookieJar;
public abstract fun getDns ()Lokhttp3/Dns;
public abstract fun getHostnameVerifier ()Ljavax/net/ssl/HostnameVerifier;
public abstract fun getProxy ()Ljava/net/Proxy;
public abstract fun getProxyAuthenticator ()Lokhttp3/Authenticator;
public abstract fun getProxySelector ()Ljava/net/ProxySelector;
public abstract fun getRetryOnConnectionFailure ()Z
public abstract fun getSocketFactory ()Ljavax/net/SocketFactory;
public abstract fun getSslSocketFactory ()Ljavax/net/ssl/SSLSocketFactory;
public abstract fun getX509TrustManager ()Ljavax/net/ssl/X509TrustManager;
public abstract fun proceed (Lokhttp3/Request;)Lokhttp3/Response;
public abstract fun readTimeoutMillis ()I
public abstract fun request ()Lokhttp3/Request;
public abstract fun withAuthenticator (Lokhttp3/Authenticator;)Lokhttp3/Interceptor$Chain;
public abstract fun withCache (Lokhttp3/Cache;)Lokhttp3/Interceptor$Chain;
public abstract fun withCertificateChainCleaner (Lokhttp3/internal/tls/CertificateChainCleaner;)Lokhttp3/Interceptor$Chain;
public abstract fun withCertificatePinner (Lokhttp3/CertificatePinner;)Lokhttp3/Interceptor$Chain;
public abstract fun withConnectTimeout (ILjava/util/concurrent/TimeUnit;)Lokhttp3/Interceptor$Chain;
public abstract fun withConnectionPool (Lokhttp3/ConnectionPool;)Lokhttp3/Interceptor$Chain;
public abstract fun withCookieJar (Lokhttp3/CookieJar;)Lokhttp3/Interceptor$Chain;
public abstract fun withDns (Lokhttp3/Dns;)Lokhttp3/Interceptor$Chain;
public abstract fun withHostnameVerifier (Ljavax/net/ssl/HostnameVerifier;)Lokhttp3/Interceptor$Chain;
public abstract fun withProxy (Ljava/net/Proxy;)Lokhttp3/Interceptor$Chain;
public abstract fun withProxyAuthenticator (Lokhttp3/Authenticator;)Lokhttp3/Interceptor$Chain;
public abstract fun withProxySelector (Ljava/net/ProxySelector;)Lokhttp3/Interceptor$Chain;
public abstract fun withReadTimeout (ILjava/util/concurrent/TimeUnit;)Lokhttp3/Interceptor$Chain;
public abstract fun withRetryOnConnectionFailure (Z)Lokhttp3/Interceptor$Chain;
public abstract fun withSocketFactory (Ljavax/net/SocketFactory;)Lokhttp3/Interceptor$Chain;
public abstract fun withSslSocketFactory (Ljavax/net/ssl/SSLSocketFactory;)Lokhttp3/Interceptor$Chain;
public abstract fun withWriteTimeout (ILjava/util/concurrent/TimeUnit;)Lokhttp3/Interceptor$Chain;
public abstract fun withX509TrustManager (Ljavax/net/ssl/X509TrustManager;)Lokhttp3/Interceptor$Chain;
public abstract fun writeTimeoutMillis ()I
}

Expand Down
30 changes: 30 additions & 0 deletions okhttp/api/jvm/okhttp.api
Original file line number Diff line number Diff line change
Expand Up @@ -749,12 +749,42 @@ public abstract interface class okhttp3/Interceptor$Chain {
public abstract fun call ()Lokhttp3/Call;
public abstract fun connectTimeoutMillis ()I
public abstract fun connection ()Lokhttp3/Connection;
public abstract fun getAuthenticator ()Lokhttp3/Authenticator;
public abstract fun getCache ()Lokhttp3/Cache;
public abstract fun getCertificateChainCleaner ()Lokhttp3/internal/tls/CertificateChainCleaner;
public abstract fun getCertificatePinner ()Lokhttp3/CertificatePinner;
public abstract fun getConnectionPool ()Lokhttp3/ConnectionPool;
public abstract fun getCookieJar ()Lokhttp3/CookieJar;
public abstract fun getDns ()Lokhttp3/Dns;
public abstract fun getHostnameVerifier ()Ljavax/net/ssl/HostnameVerifier;
public abstract fun getProxy ()Ljava/net/Proxy;
public abstract fun getProxyAuthenticator ()Lokhttp3/Authenticator;
public abstract fun getProxySelector ()Ljava/net/ProxySelector;
public abstract fun getRetryOnConnectionFailure ()Z
public abstract fun getSocketFactory ()Ljavax/net/SocketFactory;
public abstract fun getSslSocketFactory ()Ljavax/net/ssl/SSLSocketFactory;
public abstract fun getX509TrustManager ()Ljavax/net/ssl/X509TrustManager;
public abstract fun proceed (Lokhttp3/Request;)Lokhttp3/Response;
public abstract fun readTimeoutMillis ()I
public abstract fun request ()Lokhttp3/Request;
public abstract fun withAuthenticator (Lokhttp3/Authenticator;)Lokhttp3/Interceptor$Chain;
public abstract fun withCache (Lokhttp3/Cache;)Lokhttp3/Interceptor$Chain;
public abstract fun withCertificateChainCleaner (Lokhttp3/internal/tls/CertificateChainCleaner;)Lokhttp3/Interceptor$Chain;
public abstract fun withCertificatePinner (Lokhttp3/CertificatePinner;)Lokhttp3/Interceptor$Chain;
public abstract fun withConnectTimeout (ILjava/util/concurrent/TimeUnit;)Lokhttp3/Interceptor$Chain;
public abstract fun withConnectionPool (Lokhttp3/ConnectionPool;)Lokhttp3/Interceptor$Chain;
public abstract fun withCookieJar (Lokhttp3/CookieJar;)Lokhttp3/Interceptor$Chain;
public abstract fun withDns (Lokhttp3/Dns;)Lokhttp3/Interceptor$Chain;
public abstract fun withHostnameVerifier (Ljavax/net/ssl/HostnameVerifier;)Lokhttp3/Interceptor$Chain;
public abstract fun withProxy (Ljava/net/Proxy;)Lokhttp3/Interceptor$Chain;
public abstract fun withProxyAuthenticator (Lokhttp3/Authenticator;)Lokhttp3/Interceptor$Chain;
public abstract fun withProxySelector (Ljava/net/ProxySelector;)Lokhttp3/Interceptor$Chain;
public abstract fun withReadTimeout (ILjava/util/concurrent/TimeUnit;)Lokhttp3/Interceptor$Chain;
public abstract fun withRetryOnConnectionFailure (Z)Lokhttp3/Interceptor$Chain;
public abstract fun withSocketFactory (Ljavax/net/SocketFactory;)Lokhttp3/Interceptor$Chain;
public abstract fun withSslSocketFactory (Ljavax/net/ssl/SSLSocketFactory;)Lokhttp3/Interceptor$Chain;
public abstract fun withWriteTimeout (ILjava/util/concurrent/TimeUnit;)Lokhttp3/Interceptor$Chain;
public abstract fun withX509TrustManager (Ljavax/net/ssl/X509TrustManager;)Lokhttp3/Interceptor$Chain;
public abstract fun writeTimeoutMillis ()I
}

Expand Down
199 changes: 198 additions & 1 deletion okhttp/src/commonJvmAndroid/kotlin/okhttp3/Interceptor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@
package okhttp3

import java.io.IOException
import java.net.Proxy
import java.net.ProxySelector
import java.util.concurrent.TimeUnit
import javax.net.SocketFactory
import javax.net.ssl.HostnameVerifier
import javax.net.ssl.SSLSocketFactory
import javax.net.ssl.X509TrustManager
import okhttp3.internal.tls.CertificateChainCleaner

/**
* Observes, modifies, and potentially short-circuits requests going out and the corresponding
Expand Down Expand Up @@ -75,38 +82,228 @@ fun interface Interceptor {
}

interface Chain {
/**
* Returns the request being executed.
*/
fun request(): Request

@Throws(IOException::class)
fun proceed(request: Request): Response

/**
* Returns the connection the request will be executed on. This is only available in the chains
* of network interceptors; for application interceptors this is always null.
* of network interceptors. For application interceptors this is always null.
*/
fun connection(): Connection?

/**
* Returns the `Call` to which this chain belongs.
*/
fun call(): Call

/**
* Returns the connect timeout in milliseconds.
*/
fun connectTimeoutMillis(): Int

/**
* Returns a new chain with the specified connect timeout.
*/
fun withConnectTimeout(
timeout: Int,
unit: TimeUnit,
): Chain

/**
* Returns the read timeout in milliseconds.
*/
fun readTimeoutMillis(): Int

/**
* Returns a new chain with the specified read timeout.
*/
fun withReadTimeout(
timeout: Int,
unit: TimeUnit,
): Chain

/**
* Returns the write timeout in milliseconds.
*/
fun writeTimeoutMillis(): Int

/**
* Returns a new chain with the specified write timeout.
*/
fun withWriteTimeout(
timeout: Int,
unit: TimeUnit,
): Chain

/**
* Get the [DNS] instance for the OkHttpClient, or an override from the Call.Chain.
*/
val dns: Dns

/**
* Override the [DNS] for the Call.Chain.
*
* @throws IllegalStateException if this is a Network Interceptor, since the override is too late.
*/
fun withDns(dns: Dns): Chain

/**
* Returns the [SocketFactory] for the OkHttpClient, or an override from the Call.Chain.
*/
val socketFactory: SocketFactory

/**
* Override the [SocketFactory] for the Call.Chain.
*
* @throws IllegalStateException if this is a Network Interceptor, since the override is too late.
*/
fun withSocketFactory(socketFactory: SocketFactory): Chain

/**
* Returns true if the call should retry on connection failures.
*/
val retryOnConnectionFailure: Boolean

/**
* Returns a new chain with the specified retry on connection failure setting.
*/
fun withRetryOnConnectionFailure(retryOnConnectionFailure: Boolean): Chain

/**
* Returns the [Authenticator] for the OkHttpClient, or an override from the Call.Chain.
*/
val authenticator: Authenticator

/**
* Override the [Authenticator] for the Call.Chain.
*
* @throws IllegalStateException if this is a Network Interceptor, since the override is too late.
*/
fun withAuthenticator(authenticator: Authenticator): Chain

/**
* Returns the [CookieJar] for the OkHttpClient, or an override from the Call.Chain.
*/
val cookieJar: CookieJar

/**
* Returns a new chain with the specified [CookieJar].
*/
fun withCookieJar(cookieJar: CookieJar): Chain

/**
* Returns the [Cache] for the OkHttpClient, or an override from the Call.Chain.
*/
val cache: Cache?

/**
* Override the [Cache] for the Call.Chain.
*
* @throws IllegalStateException if this is a Network Interceptor, since the override is too late.
*/
fun withCache(cache: Cache?): Chain

/**
* Returns the [Proxy] for the OkHttpClient, or an override from the Call.Chain.
*/
val proxy: Proxy?

/**
* Returns a new chain with the specified [Proxy].
*/
fun withProxy(proxy: Proxy?): Chain

/**
* Returns the [ProxySelector] for the OkHttpClient, or an override from the Call.Chain.
*/
val proxySelector: ProxySelector

/**
* Override the [ProxySelector] for the Call.Chain.
*
* @throws IllegalStateException if this is a Network Interceptor, since the override is too late.
*/
fun withProxySelector(proxySelector: ProxySelector): Chain

/**
* Returns the proxy [Authenticator] for the OkHttpClient, or an override from the Call.Chain.
*/
val proxyAuthenticator: Authenticator

/**
* Returns a new chain with the specified proxy [Authenticator].
*/
fun withProxyAuthenticator(proxyAuthenticator: Authenticator): Chain

/**
* Returns the [SSLSocketFactory] for the OkHttpClient, or an override from the Call.Chain.
*/
val sslSocketFactory: SSLSocketFactory?

/**
* Returns a new chain with the specified [SSLSocketFactory].
*
* @throws IllegalStateException if this is a Network Interceptor, since the override is too late.
*/
fun withSslSocketFactory(sslSocketFactory: SSLSocketFactory?): Chain

/**
* Returns the [X509TrustManager] for the OkHttpClient, or an override from the Call.Chain.
*/
val x509TrustManager: X509TrustManager?

/**
* Returns a new chain with the specified [X509TrustManager].
*/
fun withX509TrustManager(x509TrustManager: X509TrustManager): Chain

/**
* Returns the [HostnameVerifier] for the OkHttpClient, or an override from the Call.Chain.
*/
val hostnameVerifier: HostnameVerifier

/**
* Override the [HostnameVerifier] for the Call.Chain.
*
* @throws IllegalStateException if this is a Network Interceptor, since the override is too late.
*/
fun withHostnameVerifier(hostnameVerifier: HostnameVerifier): Chain

/**
* Returns the [CertificatePinner] for the OkHttpClient, or an override from the Call.Chain.
*/
val certificatePinner: CertificatePinner

/**
* Returns a new chain with the specified [CertificatePinner].
*/
fun withCertificatePinner(certificatePinner: CertificatePinner): Chain

/**
* Returns the [CertificateChainCleaner] for the OkHttpClient, or an override from the Call.Chain.
*/
val certificateChainCleaner: CertificateChainCleaner?

/**
* Override the [CertificateChainCleaner] for the Call.Chain.
*
* @throws IllegalStateException if this is a Network Interceptor, since the override is too late.
*/
fun withCertificateChainCleaner(certificateChainCleaner: CertificateChainCleaner): Chain

/**
* Returns the [ConnectionPool] for the OkHttpClient, or an override from the Call.Chain.
*/
val connectionPool: ConnectionPool

/**
* Returns a new chain with the specified [ConnectionPool].
*/
fun withConnectionPool(connectionPool: ConnectionPool): Chain
}
}
2 changes: 1 addition & 1 deletion okhttp/src/commonJvmAndroid/kotlin/okhttp3/OkHttpClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ open class OkHttpClient internal constructor(
@get:JvmName("socketFactory")
val socketFactory: SocketFactory = builder.socketFactory

private val sslSocketFactoryOrNull: SSLSocketFactory?
internal val sslSocketFactoryOrNull: SSLSocketFactory?

@get:JvmName("sslSocketFactory")
val sslSocketFactory: SSLSocketFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,7 @@ class RealCall(
index = 0,
exchange = null,
request = originalRequest,
connectTimeoutMillis = client.connectTimeoutMillis,
readTimeoutMillis = client.readTimeoutMillis,
writeTimeoutMillis = client.writeTimeoutMillis,
client = client,
)

var calledNoMoreExchanges = false
Expand Down Expand Up @@ -276,14 +274,17 @@ class RealCall(
RealRoutePlanner(
taskRunner = client.taskRunner,
connectionPool = connectionPool,
// TODO check if override should be used
readTimeoutMillis = client.readTimeoutMillis,
// TODO check if override should be used
writeTimeoutMillis = client.writeTimeoutMillis,
socketConnectTimeoutMillis = chain.connectTimeoutMillis,
socketReadTimeoutMillis = chain.readTimeoutMillis,
pingIntervalMillis = client.pingIntervalMillis,
// TODO check if override should be used
retryOnConnectionFailure = client.retryOnConnectionFailure,
fastFallback = client.fastFallback,
address = client.address(request.url),
address = chain.address(request.url),
routeDatabase = client.routeDatabase,
call = this,
request = request,
Expand Down
Loading
Loading