diff --git a/okhttp-testing-support/src/main/kotlin/okhttp3/internal/http/RecordingProxySelector.kt b/okhttp-testing-support/src/main/kotlin/okhttp3/internal/http/RecordingProxySelector.kt index b81d99857..a51e8afb7 100644 --- a/okhttp-testing-support/src/main/kotlin/okhttp3/internal/http/RecordingProxySelector.kt +++ b/okhttp-testing-support/src/main/kotlin/okhttp3/internal/http/RecordingProxySelector.kt @@ -30,8 +30,8 @@ import okhttp3.internal.format class RecordingProxySelector : ProxySelector() { @JvmField val proxies = mutableListOf() - private val requestedUris = mutableListOf() - private val failures = mutableListOf() + val requestedUris = mutableListOf() + val failures = mutableListOf() override fun select(uri: URI): List { requestedUris.add(uri) diff --git a/okhttp/src/main/kotlin/okhttp3/internal/connection/ConnectPlan.kt b/okhttp/src/main/kotlin/okhttp3/internal/connection/ConnectPlan.kt index b143092cc..a2815f5c1 100644 --- a/okhttp/src/main/kotlin/okhttp3/internal/connection/ConnectPlan.kt +++ b/okhttp/src/main/kotlin/okhttp3/internal/connection/ConnectPlan.kt @@ -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 { diff --git a/okhttp/src/test/java/okhttp3/CallTest.kt b/okhttp/src/test/java/okhttp3/CallTest.kt index 47d1dc91d..c483e5843 100644 --- a/okhttp/src/test/java/okhttp3/CallTest.kt +++ b/okhttp/src/test/java/okhttp3/CallTest.kt @@ -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 */