提交 80e1309c 编写于 作者: J jackjintai

modify:

1、修复拦截器重复调用的问题
上级 06562162
...@@ -42,7 +42,8 @@ public class HttpUrlConnectionProxyUtil { ...@@ -42,7 +42,8 @@ public class HttpUrlConnectionProxyUtil {
private static URLConnection createOkHttpURLConnection(URLConnection urlConnection) throws Exception { private static URLConnection createOkHttpURLConnection(URLConnection urlConnection) throws Exception {
OkHttpClient.Builder builder = new OkHttpClient.Builder(); OkHttpClient.Builder builder = new OkHttpClient.Builder();
addInterceptor(builder); //不需要再重复添加拦截器 因为已经通过字节码主如果拦截器了
//addInterceptor(builder);
OkHttpClient mClient = builder.build(); OkHttpClient mClient = builder.build();
String strUrl = urlConnection.getURL().toString(); String strUrl = urlConnection.getURL().toString();
...@@ -63,19 +64,20 @@ public class HttpUrlConnectionProxyUtil { ...@@ -63,19 +64,20 @@ public class HttpUrlConnectionProxyUtil {
private static void addInterceptor(OkHttpClient.Builder builder) { private static void addInterceptor(OkHttpClient.Builder builder) {
// 判断当前是否已经添加了拦截器,如果已添加则返回 // 判断当前是否已经添加了拦截器,如果已添加则返回
for (Interceptor interceptor : builder.interceptors()) { for (Interceptor interceptor : builder.interceptors()) {
if (interceptor instanceof DoraemonInterceptor) { if (interceptor instanceof MockInterceptor) {
return; return;
} }
} }
builder builder
//添加mock拦截器 //添加mock拦截器
.addInterceptor(new MockInterceptor()) .addInterceptor(new MockInterceptor())
//添加大图检测拦截器 //添加大图检测拦截器
.addInterceptor(new LargePictureInterceptor()) .addInterceptor(new LargePictureInterceptor())
//添加弱网 拦截器
.addNetworkInterceptor(new DoraemonWeakNetworkInterceptor())
//添加dokit拦截器 //添加dokit拦截器
.addInterceptor(new DoraemonInterceptor()); .addInterceptor(new DoraemonInterceptor())
//添加弱网 拦截器
.addNetworkInterceptor(new DoraemonWeakNetworkInterceptor());
} }
/** /**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册