-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Allow OkHttpClient overrides in Interceptor #9108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+1,497
−65
Merged
Changes from 15 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
4a425f7
Allow OkHttpClient overrides in Interceptor
yschimke 2dfddae
cleanup
yschimke 625589a
Merge branch 'master' into with_dns
yschimke 7abf8ee
all fields
yschimke 01641c1
Merge branch 'master' into with_dns
yschimke a964f63
Add test
yschimke 76d0023
Add test
yschimke dba52bc
cleanup
yschimke e175b8e
Fix tests
yschimke 638a2de
Fix api checks
yschimke cc76f02
Merge branch 'master' into with_dns
yschimke b1473e7
Fixes and start on test
yschimke d13d0ee
Add more tests
yschimke c2b7479
comments
yschimke 27a8d60
comments
yschimke c28672a
Add tests to work through
yschimke 0c665c1
revert
yschimke d450c1b
More testing
yschimke e86a858
simplify test
yschimke 101e588
Fix test
yschimke adf491b
Merge branch 'master' into with_dns
yschimke 40ee3db
cleanup
yschimke efd106c
Use interceptor for redirect flags
yschimke 769cf19
Cleanup
yschimke 5894c95
Fix test
yschimke b66f05a
Merge branch 'master' into with_dns
yschimke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -82,31 +89,201 @@ fun interface Interceptor { | |
|
|
||
| /** | ||
| * 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. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
| timeout: Long, | ||
| 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, | ||
| timeout: Long, | ||
| 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, | ||
| timeout: Long, | ||
| unit: TimeUnit, | ||
| ): Chain | ||
|
|
||
| /** | ||
| * Get the [DNS] instance for the OkHttpClient, or an override from the Call.Chain. | ||
| */ | ||
| val dns: Dns | ||
yschimke marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * 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. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 sslSocketFactoryOrNull: 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?, x509TrustManager: X509TrustManager?): Chain | ||
|
|
||
| /** | ||
| * Returns the [X509TrustManager] for the OkHttpClient, or an override from the Call.Chain. | ||
| */ | ||
| val x509TrustManagerOrNull: X509TrustManager? | ||
|
|
||
| /** | ||
| * 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 [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 | ||
yschimke marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file must never have red in it