|
6 | 6 | import com.qiniu.util.StringUtils; |
7 | 7 | import okhttp3.*; |
8 | 8 | import okio.BufferedSink; |
| 9 | +import qiniu.happydns.DnsClient; |
| 10 | +import qiniu.happydns.Domain; |
9 | 11 |
|
10 | 12 | import java.io.File; |
11 | 13 | import java.io.IOException; |
| 14 | +import java.net.InetAddress; |
| 15 | +import java.net.UnknownHostException; |
| 16 | +import java.util.ArrayList; |
| 17 | +import java.util.Collections; |
| 18 | +import java.util.List; |
12 | 19 | import java.util.concurrent.TimeUnit; |
13 | 20 |
|
14 | 21 | /** |
@@ -46,10 +53,32 @@ public okhttp3.Response intercept(Chain chain) throws IOException { |
46 | 53 | return response; |
47 | 54 | } |
48 | 55 | }); |
| 56 | + if (Config.dns != null) { |
| 57 | + final DnsClient d = Config.dns; |
| 58 | + builder.dns(new Dns() { |
| 59 | + @Override |
| 60 | + public List<InetAddress> lookup(String hostname) throws UnknownHostException { |
| 61 | + InetAddress[] ips; |
| 62 | + try { |
| 63 | + ips = d.queryInetAddress(new Domain(hostname)); |
| 64 | + } catch (IOException e) { |
| 65 | + e.printStackTrace(); |
| 66 | + throw new UnknownHostException(e.getMessage()); |
| 67 | + } |
| 68 | + if (ips == null) { |
| 69 | + throw new UnknownHostException(hostname + " resolve failed"); |
| 70 | + } |
| 71 | + List<InetAddress> l = new ArrayList<>(); |
| 72 | + Collections.addAll(l, ips); |
| 73 | + return l; |
| 74 | + } |
| 75 | + }); |
| 76 | + } |
49 | 77 | builder.connectTimeout(Config.CONNECT_TIMEOUT, TimeUnit.SECONDS); |
50 | 78 | builder.readTimeout(Config.RESPONSE_TIMEOUT, TimeUnit.SECONDS); |
51 | 79 | builder.writeTimeout(Config.WRITE_TIMEOUT, TimeUnit.SECONDS); |
52 | 80 | httpClient = builder.build(); |
| 81 | + |
53 | 82 | } |
54 | 83 |
|
55 | 84 | private static String userAgent() { |
|
0 commit comments