httpdns 缓存策略,特殊接口获取 httpdns 服务
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
package com.mogo.utils.network;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import okhttp3.ConnectionPool;
|
||||
import okhttp3.Dns;
|
||||
import okhttp3.Interceptor;
|
||||
import okhttp3.OkHttpClient;
|
||||
@@ -52,7 +52,11 @@ public final class OkHttpFactory {
|
||||
HttpDns httpDns = NetConfig.instance().getHttpDns();
|
||||
if ( httpDns != null ) {
|
||||
builder.dns( hostname -> {
|
||||
return httpDns.lookup( hostname );
|
||||
List< InetAddress > addresses = httpDns.lookup( hostname );
|
||||
if ( addresses != null && !addresses.isEmpty() ) {
|
||||
return addresses;
|
||||
}
|
||||
return Dns.SYSTEM.lookup( hostname );
|
||||
} );
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user