Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*/
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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These docs describe the implementation mechanism, but not the purpose.

I’d prefer, ‘Returns the cookie jar that'll be used for this call’

*/
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
}
}
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