Last active
August 23, 2022 12:46
-
-
Save kamoljan/80e429cc50d8465a217ac12319711e23 to your computer and use it in GitHub Desktop.
An example for DNS over HTTPS with OkHttp for Android in Kotlin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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