修改httpdns解析实现,目前以域名转域名方式访问
This commit is contained in:
@@ -19,4 +19,6 @@ public class OchBusRoutesResponse extends BaseData {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ public class OchBusPresenter extends Presenter<OchBusFragment> {
|
||||
super.onSuccess(o);
|
||||
Logger.d(TAG, "获取到小巴路线数据: " + o);
|
||||
if (mView != null) {
|
||||
mView.refreshBusStations(o.getResult().getSiteData());
|
||||
// mView.refreshBusStations(o.getResult().getSiteData());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -66,6 +66,16 @@ public interface IMogoHttpDns extends IProvider {
|
||||
@Keep
|
||||
void getHttpDnsIp(String host, int type, boolean useCache, IHttpDnsCallback callback);
|
||||
|
||||
/**
|
||||
* 同步进行dns解析,无需回调
|
||||
* @param host
|
||||
* @param type
|
||||
* @param useCache
|
||||
*
|
||||
* @return ip:port
|
||||
*/
|
||||
String syncGetHttpDns(String host, int type, boolean useCache);
|
||||
|
||||
// /**
|
||||
// * 监听 ttl 回调
|
||||
// *
|
||||
|
||||
@@ -49,6 +49,22 @@ public class MogoHttpDns implements IMogoHttpDns, HttpDns, OnAddressChangedListe
|
||||
return httpDnsHelper.getHttpDnsCachedAddress(type, host);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String syncGetHttpDns(String host, int type, boolean useCache) {
|
||||
Logger.d("MogoHttpDns", "getHttpDnsIp host: " + host + " type: " + type);
|
||||
Map<String, String> map = httpDnsHelper.getAllAddress();
|
||||
if (useCache) {
|
||||
String address = httpDnsHelper.getHttpDnsCachedAddress(type, host);
|
||||
if (address != null) {
|
||||
return address;
|
||||
} else {
|
||||
return httpDnsHelper.getHttpDnsAddress(type, host);
|
||||
}
|
||||
} else {
|
||||
return httpDnsHelper.getHttpDnsAddress(type, host);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getHttpDnsIp(String host, int type, boolean useCache, IHttpDnsCallback callback) {
|
||||
Logger.d("MogoHttpDns", "getHttpDnsIp host: " + host + " type: " + type);
|
||||
@@ -96,7 +112,7 @@ public class MogoHttpDns implements IMogoHttpDns, HttpDns, OnAddressChangedListe
|
||||
public HttpDnsSimpleLocation getCurrentLocation() {
|
||||
HttpSimpleLocation simpleLocation = locationChanged.getLocation();
|
||||
if (simpleLocation != null) {
|
||||
return new HttpDnsSimpleLocation(simpleLocation.getCityCode(), simpleLocation.getLat(), simpleLocation.getLon());
|
||||
return new HttpDnsSimpleLocation("010", simpleLocation.getLat(), simpleLocation.getLon());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.content.Context;
|
||||
import com.alibaba.android.arouter.facade.annotation.Route;
|
||||
import com.mogo.httpdns.HttpDnsConst;
|
||||
import com.mogo.httpdns.IHttpDnsCallback;
|
||||
import com.mogo.httpdns.IHttpDnsLocationChanged;
|
||||
import com.mogo.httpdns.IHttpDnsTtlCallback;
|
||||
import com.mogo.httpdns.IMogoHttpDns;
|
||||
import com.mogo.utils.network.HttpDns;
|
||||
@@ -29,6 +30,11 @@ class HttpDnsNoop implements IMogoHttpDns {
|
||||
return host;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String syncGetHttpDns(String host, int type, boolean useCache) {
|
||||
return host;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getHttpDnsIp( String host,int type, boolean useCache, IHttpDnsCallback callback ) {
|
||||
if ( callback != null ) {
|
||||
@@ -46,6 +52,11 @@ class HttpDnsNoop implements IMogoHttpDns {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(Context context, IHttpDnsLocationChanged locationChanged) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init( Context context ) {
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ import com.mogo.commons.network.Constants;
|
||||
import com.mogo.commons.network.ParamsUtil;
|
||||
import com.mogo.commons.network.X509TrustManagerImpl;
|
||||
import com.mogo.commons.storage.SpStorage;
|
||||
import com.mogo.httpdns.HttpDnsConst;
|
||||
import com.mogo.httpdns.IMogoHttpDns;
|
||||
import com.mogo.httpdns.MogoHttpDnsHandler;
|
||||
import com.mogo.utils.ThreadPoolService;
|
||||
@@ -178,7 +179,16 @@ public abstract class AbsMogoApplication extends Application {
|
||||
.build();
|
||||
return chain.proceed( request );
|
||||
} )
|
||||
.setHttpDns( dns.dns() )
|
||||
// 增加域名->域名的转换方式,暂时去掉httpdns方式
|
||||
.addInterceptor(chain -> {
|
||||
Request request = chain.request();
|
||||
String path = request.url().encodedPath();
|
||||
String host = "http://" + dns.syncGetHttpDns(request.url().host().replace("http://", "").replace("https://", ""), HttpDnsConst.HTTP_DNS_ADDRESS_TYPE_HTTP, true);
|
||||
String url = host + path;
|
||||
Logger.d("DomainExchange", "oriHost: " + request.url().host() + " newHost: " + host+" \r\n newUrl: "+url);
|
||||
return chain.proceed(request.newBuilder().url(url).build());
|
||||
})
|
||||
.setHttpDns( null )
|
||||
.setLoggable( DebugConfig.isDebug() );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user