-
Notifications
You must be signed in to change notification settings - Fork 9.3k
fix DoH error when using ip address as hostname #7073
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
Changes from 6 commits
f74fa03
37be7f2
f26f1cd
1adcb89
2cf4de1
47f50f5
d0fb591
8158e31
d9bb9fd
9614b50
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -32,6 +32,7 @@ import okhttp3.Protocol | |||
| import okhttp3.Request | ||||
| import okhttp3.RequestBody.Companion.toRequestBody | ||||
| import okhttp3.Response | ||||
| import okhttp3.internal.canParseAsIpAddress | ||||
| import okhttp3.internal.platform.Platform | ||||
| import okhttp3.internal.publicsuffix.PublicSuffixDatabase | ||||
|
|
||||
|
|
@@ -53,6 +54,7 @@ class DnsOverHttps internal constructor( | |||
| @get:JvmName("resolvePrivateAddresses") val resolvePrivateAddresses: Boolean, | ||||
| @get:JvmName("resolvePublicAddresses") val resolvePublicAddresses: Boolean | ||||
| ) : Dns { | ||||
|
|
||||
| @Throws(UnknownHostException::class) | ||||
| override fun lookup(hostname: String): List<InetAddress> { | ||||
| if (!resolvePrivateAddresses || !resolvePublicAddresses) { | ||||
|
|
@@ -67,7 +69,24 @@ class DnsOverHttps internal constructor( | |||
| } | ||||
| } | ||||
|
|
||||
| return lookupHttps(hostname) | ||||
| return try { | ||||
| lookupHttps(hostname) | ||||
| } catch (bestFailure: UnknownHostException) { | ||||
| val address = if (hostname.startsWith("[") && hostname.endsWith("]")) { | ||||
| hostname.substring(1, hostname.length - 1) | ||||
| } else { | ||||
| hostname | ||||
| } | ||||
| if (address.canParseAsIpAddress()) { | ||||
|
||||
| assertThat(parse("http://[::1]/").host()).isEqualTo("::1"); |
Which confirms the HttpUrl strips the [].
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.
Do you mean that the HttpUrl will handle the square braces before calling dns lookup, so we don't need to check and strips the [] here and just remove the test case for hostname "[::1]"?
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.
nit: Can you revert this line.