-
Response response = getResponseWithInterceptorChain();
-
if (retryAndFollowUpInterceptor.isCanceled()) {
-
signalledCallback = true;
-
responseCallback.onFailure(RealCall.this, new IOException(“Canceled”));
-
} else {
-
signalledCallback = true;
-
responseCallback.onResponse(RealCall.this, response);
-
}
-
} catch (IOException e) {
-
if (signalledCallback) {
-
// Do not signal the callback twice!
-
Platform.get().log(INFO, "Callback failure for " + toLoggableString(), e);
-
} else {
-
responseCallback.onFailure(RealCall.this, e);
-
}
-
} finally {
-
client.dispatcher().finished(this);
-
}
-
}
-
}
execute方法的逻辑并不复杂,简单的说就是:
调用getResponseWithInterceptorChain获取服务器返回
通知任务分发器(client.dispatcher)该任务已结束
getResponseWithInterceptorChain构建了一个拦截器链,通过依次执行该拦截器链中的每一个拦截器最终得到服务器返回。
3. 构建拦截器链
首先来看下getResponseWithInterceptorChain的实现:
源码路径:okhttp3/RealCall.java
// 开始执行整个请求
Response getResponseWithInterceptorChain() thro