Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions okhttp/src/test/java/okhttp3/CallTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 */
Expand Down