Skip to content
Open
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 @@ -221,7 +221,14 @@ class RouteSelector internal constructor(
else -> socketPort
}

val dnsRequest = Dns.Request(socketHost, dnsPort)
val dnsRequest =
try {
Dns.Request(socketHost, dnsPort)
} catch (e: IllegalArgumentException) {
throw UnknownHostException("invalid host $socketHost.").apply {
initCause(e)
}
}
val result =
when (val dnsCall = address.dns.newCall(dnsRequest)) {
is LookupDnsCall -> {
Expand Down
16 changes: 16 additions & 0 deletions okhttp/src/jvmTest/kotlin/okhttp3/CallTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import java.net.CookiePolicy
import java.net.HttpCookie
import java.net.HttpURLConnection
import java.net.InetAddress
import java.net.InetSocketAddress
import java.net.ProtocolException
import java.net.Proxy
import java.net.SocketTimeoutException
Expand Down Expand Up @@ -1072,6 +1073,21 @@ open class CallTest {
}
}

/** https://github.com/lysine-dev/okhttp/issues/9758 */
@Test
fun malformedProxyHostnameFailsGracefully() {
val proxySelector = RecordingProxySelector()
proxySelector.proxies.add(
Proxy(
Proxy.Type.HTTP,
InetSocketAddress.createUnresolved("internet ", 8080),
),
)
client = client.newBuilder().proxySelector(proxySelector).build()
executeSynchronously(server.url("/").toString())
.assertFailure(UnknownHostException::class.java)
}

/** https://github.com/lysine-dev/okhttp/issues/4875 */
@Test
fun interceptorRecoversWhenRoutesExhausted() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Assumptions.assumeTrue
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import org.junit.jupiter.api.extension.RegisterExtension

@Burst
Expand Down Expand Up @@ -479,6 +480,20 @@ class RouteSelectorTest(
assertThat(routeSelector.hasNext()).isFalse()
}

@Test fun failedRouteWithInvalidProxy() {
val address =
factory.newAddress(
proxy =
Proxy(
Proxy.Type.HTTP,
InetSocketAddress.createUnresolved("a b", 8080),
),
)
val routeSelector = newRouteSelector(address)

assertThrows<UnknownHostException> { routeSelector.next() }
}

@Test fun queryForAllSelectedRoutes() {
val address = factory.newAddress()
val routeSelector = newRouteSelector(address)
Expand Down