|
52 | 52 | public class Http { |
53 | 53 | private static final String TAG = "Http"; |
54 | 54 | private static final OkHttpClient httpClient; |
| 55 | + private static final OkHttpClient httpClientDoH; |
55 | 56 | private static final OkHttpClient httpClientWithCache; |
| 57 | + private static final OkHttpClient httpClientWithCacheDoH; |
56 | 58 | private static final FallBackDNS fallbackDNS; |
57 | 59 | private static final String androidacyUA; |
| 60 | + private static boolean doh; |
58 | 61 |
|
59 | 62 | static { |
60 | 63 | MainApplication mainApplication = MainApplication.getINSTANCE(); |
@@ -131,26 +134,33 @@ public class Http { |
131 | 134 | return chain.proceed(request.build()); |
132 | 135 | }); |
133 | 136 | // Fallback DNS cache responses in case request fail but already succeeded once in the past |
134 | | - httpclientBuilder.dns(fallbackDNS = new FallBackDNS(mainApplication, dns, |
| 137 | + fallbackDNS = new FallBackDNS(mainApplication, dns, |
135 | 138 | "github.com", "api.github.com", "raw.githubusercontent.com", |
136 | 139 | "camo.githubusercontent.com", "user-images.githubusercontent.com", |
137 | 140 | "cdn.jsdelivr.net", "img.shields.io", "magisk-modules-repo.github.io", |
138 | | - "www.androidacy.com", "api.androidacy.com")); |
| 141 | + "www.androidacy.com", "api.androidacy.com"); |
139 | 142 | httpclientBuilder.cookieJar(new CDNCookieJar(true)); |
| 143 | + httpclientBuilder.dns(Dns.SYSTEM); |
140 | 144 | httpClient = httpclientBuilder.build(); |
| 145 | + httpclientBuilder.dns(fallbackDNS); |
| 146 | + httpClientDoH = httpclientBuilder.build(); |
141 | 147 | httpclientBuilder.cache(new Cache( |
142 | 148 | new File(mainApplication.getCacheDir(), "http_cache"), |
143 | 149 | 16L * 1024L * 1024L)); // 16Mib of cache |
| 150 | + httpclientBuilder.dns(Dns.SYSTEM); |
144 | 151 | httpClientWithCache = httpclientBuilder.build(); |
| 152 | + httpclientBuilder.dns(fallbackDNS); |
| 153 | + httpClientWithCacheDoH = httpclientBuilder.build(); |
145 | 154 | Log.i(TAG, "Initialized Http successfully!"); |
| 155 | + doh = MainApplication.isDohEnabled(); |
146 | 156 | } |
147 | 157 |
|
148 | 158 | public static OkHttpClient getHttpClient() { |
149 | | - return httpClient; |
| 159 | + return doh ? httpClientDoH : httpClient; |
150 | 160 | } |
151 | 161 |
|
152 | 162 | public static OkHttpClient getHttpClientWithCache() { |
153 | | - return httpClientWithCache; |
| 163 | + return doh ? httpClientWithCacheDoH : httpClientWithCache; |
154 | 164 | } |
155 | 165 |
|
156 | 166 | public static byte[] doHttpGet(String url,boolean allowCache) throws IOException { |
@@ -241,6 +251,11 @@ public static String getAndroidacyUA() { |
241 | 251 | return androidacyUA; |
242 | 252 | } |
243 | 253 |
|
| 254 | + public static void setDoh(boolean doh) { |
| 255 | + Log.d(TAG, "DoH: " + Http.doh + " -> " + doh); |
| 256 | + Http.doh = doh; |
| 257 | + } |
| 258 | + |
244 | 259 | /** |
245 | 260 | * Cookie jar that allow CDN cookies, reset on app relaunch |
246 | 261 | * Note: An argument can be made that it allow tracking but |
|
0 commit comments