Disable DoH upon failure

This commit is contained in:
topjohnwu 2020-09-13 03:46:06 -07:00
parent 60e1e07e87
commit 8a61ae621d

View File

@ -22,6 +22,7 @@ import retrofit2.Retrofit
import retrofit2.converter.moshi.MoshiConverterFactory import retrofit2.converter.moshi.MoshiConverterFactory
import retrofit2.converter.scalars.ScalarsConverterFactory import retrofit2.converter.scalars.ScalarsConverterFactory
import java.net.InetAddress import java.net.InetAddress
import java.net.UnknownHostException
val networkingModule = module { val networkingModule = module {
single { createOkHttpClient(get()) } single { createOkHttpClient(get()) }
@ -62,10 +63,16 @@ fun createOkHttpClient(context: Context): OkHttpClient {
.resolvePrivateAddresses(true) /* To make PublicSuffixDatabase never used */ .resolvePrivateAddresses(true) /* To make PublicSuffixDatabase never used */
.build() .build()
var skipDoH = false
builder.dns { hostname -> builder.dns { hostname ->
// Only resolve via DoH for known DNS polluted hostnames // Only resolve via DoH for known DNS polluted hostnames
if (hostname == "raw.githubusercontent.com") { if (!skipDoH && hostname == "raw.githubusercontent.com") {
try {
doh.lookup(hostname) doh.lookup(hostname)
} catch (e: UnknownHostException) {
skipDoH = true
Dns.SYSTEM.lookup(hostname)
}
} else { } else {
Dns.SYSTEM.lookup(hostname) Dns.SYSTEM.lookup(hostname)
} }