Skip to content

Instantly share code, notes, and snippets.

@kamoljan
Last active August 23, 2022 12:46
Show Gist options
  • Save kamoljan/80e429cc50d8465a217ac12319711e23 to your computer and use it in GitHub Desktop.
Save kamoljan/80e429cc50d8465a217ac12319711e23 to your computer and use it in GitHub Desktop.
An example for DNS over HTTPS with OkHttp for Android in Kotlin
object Networking {
private val appCache = Cache(File("cacheDir", "okhttpcache"), 10 * 1024 * 1024)
private val bootstrapClient = OkHttpClient.Builder().cache(appCache).build()
private val dns = DnsOverHttps.Builder().client(bootstrapClient)
.url("https://dns.google/dns-query".toHttpUrl())
.bootstrapDnsHosts(InetAddress.getByName("8.8.4.4"), InetAddress.getByName("8.8.8.8"))
.build()
fun provideOkHttpClient(dataStorage: DataStorage): OkHttpClient {
return OkHttpClient
.Builder()
.dns(dns)
.build()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment