Okhttp的浅层架构分析
Okhttp的责任链模式和拦截器分析
Okhttp之RetryAndFollowUpInterceptor拦截器分析
Okhttp之BridgeInterceptor拦截器分析
Okhttp之CacheInterceptor拦截器分析
Okhttp之ConnectInterceptor拦截器分析
Okhttp之网络连接相关三大类RealConnection、ConnectionPool、StreamAllocation
Okhttp之CallServerInterceptor拦截器分析
浅析okio的架构和源码实现
ConnectInterceptor连接拦截器,这里主要做的工作是创建连接
public final class ConnectInterceptor implements Interceptor {
@Override
public Response intercept(Chain chain) throws IOException {
RealInterceptorChain realChain = (RealInterceptorChain) chain;
Request request = realChain.request();
//realChain里的streamAllocation是RetryAndFollowUpInterceptor创建的
StreamAllocation streamAllocation = realChain.streamAllocation();
// We need the network to satisfy this request. Possibly for validating a conditional GET.
//判断是否get请求
boolean doExtensiveHealthChecks = !request.method().equals("GET");
//创建流处理类httpCodec ,connection也是在这里创建的
HttpCodec httpCodec = streamAllocation.newStream(client, chain, doExtensiveHealthChecks);
//拿到链接
RealConnection connection = streamAllocation.connection();
//传到下一个拦截器
return realChain.proceed(request, streamAllocation, httpCodec, connection);
}
}
ConnectInterceptor在Request阶段建立连接,处理方式也很简单,创建了两个对象:
1.HttpCodec:用来编码HTTP requests和解码HTTP responses
2.RealConnection:连接对象,负责发起与服务器的连接。
网友评论