Okhttp链接池的使用,移动安全入门

本文详细探讨了OkHttp的连接池管理,包括连接的复用条件、证书匹配策略以及清理回收机制。同时,文章也触及移动安全方面,如避免证书授权错误和防止内存泄露。通过对put、get和cleanup方法的分析,阐述了如何有效地利用和维护连接池,以提高网络性能。
摘要由CSDN通过智能技术生成
  1. 这个连接的服务器证书授权中,必须包括新的主机。
  2. 锁定证书(certificatePinner)必须匹配主机

public boolean isEligible(Address address, @Nullable Route route) {
// If this connection is not accepting new streams, we’re done.
if (allocations.size() >= allocationLimit || noNewStreams) return false;

// If the non-host fields of the address don’t overlap, we’re done.
if (!Internal.instance.equalsNonHost(this.route.address(), address)) return false;

// If the host exactly matches, we’re done: this connection can carry the address.
if (address.url().host().equals(this.route().address().url().host())) {
return true; // This connection is a perfect match.
}

// At this point we don’t have a hostname match. But we still be able to carry the request if
// our connection coalescing requirements are met. See also:
// https://hpbn.co/optimizing-application-delivery/#eliminate-domain-sharding
// https://daniel.haxx.se/blog/2016/08/18/http2-connection-coalescing/

// 1. This connection must be HTTP/2.
if (http2Connection == null) return false;

// 2. The routes must share an IP address. This requires us to have a DNS address for both
// hosts, which only happens after route planning. We can’t coalesce connections that use a
// proxy, since proxies don’t tell us the origin server’s IP address.
if (route == null) return false;
if (route.proxy().type() != Proxy

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值