使用的是阻塞io、进行了tcp复用(connection缓存)。
核心Interceptor工作
其核心是通过拦截器工作的。构建的链进行逐个调用。
Response getResponseWithInterceptorChain() throws IOException {
// Build a full stack of interceptors.
List<Interceptor> interceptors = new ArrayList<>();
interceptors.addAll(client.interceptors());
interceptors.add(retryAndFollowUpInterceptor);
interceptors.add(new BridgeInterceptor(client.cookieJar()));
interceptors.add(new CacheInterceptor(client.internalCache()));
interceptors.add(new ConnectInterceptor(client));
if (!forWebSocket) {
interceptors.addAll(client.networkInterceptors());
}
interceptors.add(new CallServerInterceptor(forWebSocket));
Interceptor.Chain chain = new RealInterceptorChain(interceptors, null, null, null, 0,
originalRequest, this, eventListener, client.connectTimeoutMillis(),
client.readTimeoutMillis(), client.writeTimeoutMillis());
return chain.proceed(originalRequest);
}
缓存问题
响应结果的缓存
内部会缓存httpresponse允许缓存的结果,比如头部携带允许cache,则可以把结果缓存下来。
如果再次请求返回的是304,没有携带内容,则直接使用。
这一块和协议勾搭的比较深,没详细分析。
Connection的缓存
在内部做分发的时候会根据地址找到对应的connection,也会进行缓