OkHttp源码分析

 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
	
	


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值