mirror of
https://github.com/square/okhttp.git
synced 2025-08-07 12:42:57 +03:00
Call proxy selector on failure (#8415)
* Call proxy selector on failure --------- Co-authored-by: Jesse Wilson <jesse@swank.ca>
This commit is contained in:
@@ -30,8 +30,8 @@ import okhttp3.internal.format
|
||||
class RecordingProxySelector : ProxySelector() {
|
||||
@JvmField val proxies = mutableListOf<Proxy>()
|
||||
|
||||
private val requestedUris = mutableListOf<URI>()
|
||||
private val failures = mutableListOf<String>()
|
||||
val requestedUris = mutableListOf<URI>()
|
||||
val failures = mutableListOf<String>()
|
||||
|
||||
override fun select(uri: URI): List<Proxy> {
|
||||
requestedUris.add(uri)
|
||||
|
@@ -141,6 +141,14 @@ class ConnectPlan(
|
||||
success = true
|
||||
return ConnectResult(plan = this)
|
||||
} catch (e: IOException) {
|
||||
// If we used the ProxySelector, and got a IOException during connect, report the failure.
|
||||
if (route.address.proxy == null && route.proxy.type() != Proxy.Type.DIRECT) {
|
||||
route.address.proxySelector.connectFailed(
|
||||
route.address.url.toUri(),
|
||||
route.proxy.address(),
|
||||
e,
|
||||
)
|
||||
}
|
||||
user.connectFailed(route, null, e)
|
||||
return ConnectResult(plan = this, throwable = e)
|
||||
} finally {
|
||||
|
@@ -15,11 +15,14 @@
|
||||
*/
|
||||
package okhttp3
|
||||
|
||||
import assertk.all
|
||||
import assertk.assertThat
|
||||
import assertk.assertions.contains
|
||||
import assertk.assertions.containsExactly
|
||||
import assertk.assertions.doesNotContain
|
||||
import assertk.assertions.hasMessage
|
||||
import assertk.assertions.hasSize
|
||||
import assertk.assertions.index
|
||||
import assertk.assertions.isCloseTo
|
||||
import assertk.assertions.isEmpty
|
||||
import assertk.assertions.isEqualTo
|
||||
@@ -30,6 +33,7 @@ import assertk.assertions.isNotNull
|
||||
import assertk.assertions.isNotSameAs
|
||||
import assertk.assertions.isNull
|
||||
import assertk.assertions.isTrue
|
||||
import assertk.assertions.matches
|
||||
import assertk.assertions.startsWith
|
||||
import assertk.fail
|
||||
import java.io.FileNotFoundException
|
||||
@@ -1017,6 +1021,12 @@ open class CallTest {
|
||||
executeSynchronously(request)
|
||||
.assertCode(200)
|
||||
.assertBody("success!")
|
||||
|
||||
assertThat(proxySelector.failures)
|
||||
.all {
|
||||
hasSize(1)
|
||||
index(0).matches(".* Connect timed out".toRegex(RegexOption.IGNORE_CASE))
|
||||
}
|
||||
}
|
||||
|
||||
/** https://github.com/square/okhttp/issues/4875 */
|
||||
|
Reference in New Issue
Block a user