Skip to content

Commit 6cf437e

Browse files
committed
fix: doh
1 parent 255ac57 commit 6cf437e

2 files changed

Lines changed: 36 additions & 11 deletions

File tree

src/main/kotlin/io/github/gnuf0rce/github/GitHubClient.kt

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ import io.ktor.client.plugins.contentnegotiation.*
2323
import io.ktor.client.request.*
2424
import io.ktor.serialization.kotlinx.json.*
2525
import kotlinx.coroutines.*
26-
import okhttp3.HttpUrl.Companion.toHttpUrl
27-
import okhttp3.OkHttpClient
28-
import okhttp3.dnsoverhttps.DnsOverHttps
2926
import java.io.*
3027
import java.net.*
3128
import kotlin.coroutines.*
@@ -93,14 +90,7 @@ public open class GitHubClient(public open val token: String?) : CoroutineScope,
9390
engine {
9491
config {
9592
proxy(this@GitHubClient.proxy)
96-
if (doh.isNotEmpty()) {
97-
dns(DnsOverHttps.Builder()
98-
.client(OkHttpClient())
99-
.url(doh.toHttpUrl())
100-
.includeIPv6(ipv6)
101-
.build()
102-
)
103-
}
93+
doh(urlString = this@GitHubClient.doh, ipv6 = this@GitHubClient.ipv6)
10494
}
10595
}
10696
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2021-2023 dsstudio Technologies and contributors.
3+
*
4+
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
5+
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
6+
*
7+
* https://github.com/gnuf0rce/github-helper/blob/master/LICENSE
8+
*/
9+
10+
11+
package io.github.gnuf0rce.github
12+
13+
import okhttp3.Dns
14+
import okhttp3.HttpUrl.Companion.toHttpUrl
15+
import okhttp3.OkHttpClient
16+
import okhttp3.dnsoverhttps.DnsOverHttps
17+
import java.net.*
18+
19+
internal fun OkHttpClient.Builder.doh(urlString: String, ipv6: Boolean) {
20+
if (urlString.isEmpty()) return
21+
val doh = DnsOverHttps.Builder()
22+
.client(OkHttpClient())
23+
.url(urlString.toHttpUrl())
24+
.includeIPv6(ipv6)
25+
.build()
26+
dns(dns = object : Dns {
27+
override fun lookup(hostname: String): List<InetAddress> {
28+
return try {
29+
doh.lookup(hostname)
30+
} catch (_: UnknownHostException) {
31+
Dns.SYSTEM.lookup(hostname)
32+
}
33+
}
34+
})
35+
}

0 commit comments

Comments
 (0)