当前位置: 首页 > news >正文

Android OkHttp 源码浅析二

OkHttp 配置参数:

 @get:JvmName("dispatcher") val dispatcher: Dispatcher = builder.dispatcher@get:JvmName("connectionPool") val connectionPool: ConnectionPool = builder.connectionPool/*** Returns an immutable list of interceptors that observe the full span of each call: from before* the connection is established (if any) until after the response source is selected (either the* origin server, cache, or both).*/@get:JvmName("interceptors") val interceptors: List<Interceptor> =builder.interceptors.toImmutableList()/*** Returns an immutable list of interceptors that observe a single network request and response.* These interceptors must call [Interceptor.Chain.proceed] exactly once: it is an error for* a network interceptor to short-circuit or repeat a network request.*/@get:JvmName("networkInterceptors") val networkInterceptors: List<Interceptor> =builder.networkInterceptors.toImmutableList()@get:JvmName("eventListenerFactory") val eventListenerFactory: EventListener.Factory =builder.eventListenerFactory@get:JvmName("retryOnConnectionFailure") val retryOnConnectionFailure: Boolean =builder.retryOnConnectionFailure@get:JvmName("authenticator") val authenticator: Authenticator = builder.authenticator@get:JvmName("followRedirects") val followRedirects: Boolean = builder.followRedirects@get:JvmName("followSslRedirects") val followSslRedirects: Boolean = builder.followSslRedirects@get:JvmName("cookieJar") val cookieJar: CookieJar = builder.cookieJar@get:JvmName("cache") val cache: Cache? = builder.cache@get:JvmName("dns") val dns: Dns = builder.dns@get:JvmName("proxy") val proxy: Proxy? = builder.proxy@get:JvmName("proxySelector") val proxySelector: ProxySelector =when {// Defer calls to ProxySelector.getDefault() because it can throw a SecurityException.builder.proxy != null -> NullProxySelectorelse -> builder.proxySelector ?: ProxySelector.getDefault() ?: NullProxySelector}@get:JvmName("proxyAuthenticator") val proxyAuthenticator: Authenticator =builder.proxyAuthenticator@get:JvmName("socketFactory") val socketFactory: SocketFactory = builder.socketFactoryprivate val sslSocketFactoryOrNull: SSLSocketFactory?@get:JvmName("sslSocketFactory") val sslSocketFactory: SSLSocketFactoryget() = sslSocketFactoryOrNull ?: throw IllegalStateException("CLEARTEXT-only client")@get:JvmName("x509TrustManager") val x509TrustManager: X509TrustManager?@get:JvmName("connectionSpecs") val connectionSpecs: List<ConnectionSpec> =builder.connectionSpecs@get:JvmName("protocols") val protocols: List<Protocol> = builder.protocols@get:JvmName("hostnameVerifier") val hostnameVerifier: HostnameVerifier = builder.hostnameVerifier@get:JvmName("certificatePinner") val certificatePinner: CertificatePinner@get:JvmName("certificateChainCleaner") val certificateChainCleaner: CertificateChainCleaner?/*** Default call timeout (in milliseconds). By default there is no timeout for complete calls, but* there is for the connect, write, and read actions within a call.*/@get:JvmName("callTimeoutMillis") val callTimeoutMillis: Int = builder.callTimeout/** Default connect timeout (in milliseconds). The default is 10 seconds. */@get:JvmName("connectTimeoutMillis") val connectTimeoutMillis: Int = builder.connectTimeout/** Default read timeout (in milliseconds). The default is 10 seconds. */@get:JvmName("readTimeoutMillis") val readTimeoutMillis: Int = builder.readTimeout/** Default write timeout (in milliseconds). The default is 10 seconds. */@get:JvmName("writeTimeoutMillis") val writeTimeoutMillis: Int = builder.writeTimeout/** Web socket and HTTP/2 ping interval (in milliseconds). By default pings are not sent. */@get:JvmName("pingIntervalMillis") val pingIntervalMillis: Int = builder.pingInterval/*** Minimum outbound web socket message size (in bytes) that will be compressed.* The default is 1024 bytes.*/@get:JvmName("minWebSocketMessageToCompress")

dispatcher 用于线程调度

connectionPool 连接池  64 个or 5 host 可以提升复用性 方便管理和提升性能

interceptors 

networkInterceptors

eventListenerFactory 事件监听器 连接建立 发送head body 等

retryOnConnectionFailure 连接 / 请求 失败是否重置

authenticator 自动认证修正 比如 401 无权限访问等 可以用于刷新token 

followRedirects 是否继续重定向 

followSslRedirects 在followRedirects 开启时 协议切换时 是否继续重定向  比如http 切换https 默认true 

cookieJar 存储器 存储cookie 默认是空实现
cache 本地缓存
dns 域名系统 域名解析为ip 函数为 lookup getAllByName List inntAddress 通过域名返回IPList---InetAddress.getAllByName(hostName)
proxy 代理 转发  代理服务器 代理多种方式 还有反向代理 类型 DIRECT 直连 HTTP SOCKS,默认NO_PROXY
proxySelector 判断是否代理 通过select 方法 返回List<Proxy> 
proxyAuthenticator 如果代理不可用 需要授权 需要验证机制
socketFactory http请求本质是java socket 通过socketFactory  创建
sslSocketFactory ssl 请求, tls ssl 加密 连接
x509TrustManager 证书验证器,通过证书和签名进行验证 ,X509 证书格式
connectionSpecs List 连接标准 规范,https 连接 客户端 发送tls 连接 的规范 比如连接套件 非对称加密等,ConnectionSpec 类定义各种规范比如 RESTRICTED_TLS支持TLS 1.3 1.2 ,MODERN_TLS1.3 1.2 ,COMPATIBLE_TLS 支持 1.3  1.2 1.1 1.0,CLEARTEXT 明文 传输https 报文 不用tls
protocols List, 支持协力的版本号 比如 1.0 , 1.1, SPDY2,SPDY3 ,HTTP2 最好使用加密 h2c ,H2_PRIOR 非加密,
hostnameVerifier: 验证合法性 域名 只验证第一个 [0] 
certificatePinner:加强验证,可以配置证书 hash 
certificateChainCleaner:=== 证书验证相关 操作X509
callTimeoutMillis 超时
connectTimeoutMillis 连接超时
readTimeoutMillis 读取超时
writeTimeoutMillis 写入超时
pingIntervalMillis 心跳机制  websocket / http2 使用

http://www.lryc.cn/news/136869.html

相关文章:

  • Python(八十四)字符串的切片操作
  • leetcode-506.相对名次-day17
  • 【QT】绘制旋转等待
  • Electron学习3 使用serialport操作串口
  • 激活函数总结(十七):激活函数补充(PELU、Phish)
  • [bug日志]springboot多模块启动,在yml配置启动端口8081,但还是启动了8080
  • 【每日易题】七夕限定——单身狗问题以及进阶问题位运算法的深入探讨
  • 消息队列前世今生 字节跳动 Kafka #创作活动
  • 『SEQ日志』在 .NET中快速集成轻量级的分布式日志平台
  • Django会话技术
  • Tree of Thoughts: Deliberate Problem Solving with Large Language Models
  • C语言刷题(13)
  • RK3568 uart串口
  • 企业数字化转型中,VR数字展厅能有哪些体验?
  • 关于cesium中tif文件处理加载在三维地图中得方式
  • JAVA结合AE(Adobe After Effects)AE模板文件解析生成视频实现类似于逗拍(视频DIY)的核心功能
  • 美容行业如何快速搭建自己的预约小程序?
  • 如何使用CSS实现一个水平居中和垂直居中的布局?
  • 关于css 的选择器和 css变量
  • 大数据技术概述(三)——编程语言的选择
  • Flutter对象状态动态监听Watcher
  • 期权分仓开户资金是否安全?具体保障措施有哪些?
  • Unity Mac踩坑日记
  • 什么是负载均衡
  • 尽管价格走势平淡,但DeFi领域仍然非常有趣
  • RCU安全引用计数
  • Linux 可重入、异步信号安全和线程安全
  • WPF中手写地图控件(3)——动态加载地图图片
  • 智慧充电桩物联网方案架构
  • C语言基础之——操作符(上)