Add dnspod (#494)

This commit is contained in:
vvb2060 2021-04-18 11:04:36 +08:00 committed by GitHub
parent d6541bb594
commit a091a43d10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 12 deletions

View File

@ -107,6 +107,11 @@ public class App extends Application {
public static OkHttpClient getOkHttpClient() { public static OkHttpClient getOkHttpClient() {
if (okHttpClient == null) { if (okHttpClient == null) {
OkHttpClient.Builder builder = new OkHttpClient.Builder().cache(getOkHttpCache()); OkHttpClient.Builder builder = new OkHttpClient.Builder().cache(getOkHttpCache());
builder.addInterceptor(chain -> {
var request = chain.request().newBuilder();
request.header("User-Agent", TAG);
return chain.proceed(request.build());
});
HttpLoggingInterceptor.Logger logger = s -> Log.v(TAG, s); HttpLoggingInterceptor.Logger logger = s -> Log.v(TAG, s);
HttpLoggingInterceptor log = new HttpLoggingInterceptor(logger); HttpLoggingInterceptor log = new HttpLoggingInterceptor(logger);
log.setLevel(HttpLoggingInterceptor.Level.HEADERS); log.setLevel(HttpLoggingInterceptor.Level.HEADERS);

View File

@ -37,19 +37,13 @@ public class DoHDNS implements Dns {
private static DnsOverHttps cloudflare; private static DnsOverHttps cloudflare;
private static DnsOverHttps tuna; private static DnsOverHttps tuna;
private static DnsOverHttps dnspod;
public DoHDNS(OkHttpClient client) { public DoHDNS(OkHttpClient client) {
cloudflare = new DnsOverHttps.Builder() var builder = new DnsOverHttps.Builder().resolvePrivateAddresses(true).client(client);
.resolvePrivateAddresses(true) cloudflare = builder.url(HttpUrl.get("https://cloudflare-dns.com/dns-query")).build();
.client(client) tuna = builder.url(HttpUrl.get("https://101.6.6.6:8443/dns-query")).build();
.url(HttpUrl.get("https://cloudflare-dns.com/dns-query")) dnspod = builder.url(HttpUrl.get("https://doh.pub/dns-query")).build();
.build();
tuna = new DnsOverHttps.Builder()
.resolvePrivateAddresses(true)
.client(client)
.url(HttpUrl.get("https://101.6.6.6:8443/dns-query"))
.build();
} }
@NonNull @NonNull
@ -62,10 +56,14 @@ public class DoHDNS implements Dns {
try { try {
if ("CN".equals(Locale.getDefault().getCountry())) if ("CN".equals(Locale.getDefault().getCountry()))
return tuna.lookup(hostname); return tuna.lookup(hostname);
} catch (UnknownHostException exception) {
try {
return dnspod.lookup(hostname);
} catch (UnknownHostException ignored) { } catch (UnknownHostException ignored) {
} }
} }
} }
}
return SYSTEM.lookup(hostname); return SYSTEM.lookup(hostname);
} }
} }