OkHttpClient通过Builder建立一个实例对象,
Request通过Builder建立一个请求对象
OkHttpClient根据Request new一个RealCall
RealCall enqueue进队列
new一个AsyncCall
AsyncCall被添加到runningAsyncCalls
executorService执行AsyncCall(也即AsyncCall的execute方法被执行)
getResponseWithInterceptorChain();
client.interceptors() ---自定义功能
retryAndFollowUpInterceptor---根据ConnectionPool、url实例化streamAllocation
BridgeInterceptor---设置一些header 设置cookie,保存cookie
CacheInterceptor---处理请求的缓存,是否从缓存取数据
ConnectInterceptor---根据streamAllocation实例化httpStream、connection
client.networkInterceptors()
CallServerInterceptor
添加的Interceptor
client.interceptors() 1
retryAndFollowUpInterceptor 2
BridgeInterceptor 3
CacheInterceptor
ConnectInterceptor
client.networkInterceptors()
CallServerInterceptor
Part
Headers headers;
String[] namesAndValues
RequestBody body;
Address
final HttpUrl url;
final Dns dns;
final SocketFactory socketFactory;
final Authenticator proxyAuthenticator;
final List<Protocol> protocols;
final List<ConnectionSpec> connectionSpecs;
final ProxySelector proxySelector;
final Proxy proxy;
final SSLSocketFactory sslSocketFactory;
final HostnameVerifier hostnameVerifier;
final CertificatePinner certificatePinner;
StreamAllocation
ConnectionPool connectionPool,
Address address
RouteSelector routeSelector
OkHttpClient
Dispatcher dispatcher
Deque<AsyncCall> runningAsyncCalls
ThreadPoolExecutor executorService
Builder
ConnectionPool connectionPool
Request
HttpUrl url
method
Headers headers
RequestBody body
tag
Builder
RealCall
OkHttpClient client
Request originalRequest
RetryAndFollowUpInterceptor retryAndFollowUpInterceptor
OkHttpClient client
AsyncCall
String name
Callback responseCallback;
RealInterceptorChain
List<Interceptor> interceptors
StreamAllocation streamAllocation
HttpStream httpStream
Connection connection
Request request
OkHttp源码分析
最新推荐文章于 2024-07-25 18:00:46 发布