Skip to content
Snippets Groups Projects
Commit 955c5a31 authored by Nathan Freitas's avatar Nathan Freitas
Browse files

update DoH support to use Cloudflare and extend timeouts

parent 1510e35e
No related branches found
No related tags found
No related merge requests found
Pipeline #1638484551 failed
......@@ -9,27 +9,33 @@ import okhttp3.Response
import okhttp3.dnsoverhttps.DnsOverHttps
import java.io.File
import java.net.InetAddress
import java.util.concurrent.TimeUnit
open class MatrixNetworkInterceptor : Interceptor {
private var dohGoog : Dns
private var dohClient : OkHttpClient
private var dohClient : Dns
private var okClient : OkHttpClient
init {
//initialize DNS over HTTPS client using Google DNS
val appCache = Cache(File("cacheDir", "okhttpcache"), 10 * 1024 * 1024)
val bootstrapClient = OkHttpClient.Builder().cache(appCache).build()
dohGoog = DnsOverHttps.Builder().client(bootstrapClient)
.url("https://dns.google/dns-query".toHttpUrl())
.bootstrapDnsHosts(InetAddress.getByName("8.8.4.4"), InetAddress.getByName("8.8.8.8"))
dohClient = DnsOverHttps.Builder().client(bootstrapClient)
.url("https://1.1.1.1/dns-query".toHttpUrl())
.bootstrapDnsHosts(InetAddress.getByName("1.1.1.1"))
.build()
dohClient = OkHttpClient.Builder().dns(dohGoog).build()
okClient = OkHttpClient.Builder()
.dns(dohClient)
.connectTimeout(1, TimeUnit.MINUTES)
.readTimeout(30, TimeUnit.SECONDS)
.writeTimeout(15, TimeUnit.SECONDS)
.build()
}
override fun intercept(chain: Interceptor.Chain): Response {
val response = dohClient.newCall(request = chain.request()).execute()
val response = okClient.newCall(request = chain.request()).execute()
return response
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment