参考文献:http://hc.apache.org/httpcomponents-client-ga/tutorial/html/
文章目录
2.连接管理
从一台主机到另一台主机建立链接的过程是非常复杂的,其中在两个端点之间有许多的包交换过程,而该过程非常耗时。建立连接时的握手产生的开销是比较明显的,特别是对于小的Http消息。如果你能够复用你建立的连接,那么这对提升整个系统的吞吐量是有很大帮助的。在HTTP/1.1 规范中,默认情况下,Http连接是可以复用的。对于使用HTTP/1.0的端点来说,可以通过keep-alive 机制来复用连接。
保持连接可用通常来说需要保证连接的持久化。HttpClient完全支持连接的持久化。
HttpClient能够直接和目标主机建立连接,同时也可以通过route(这里是指路由还是代理?)和目标主机建立连接,但这会建立许多的中间连接(也可被成为中间跳)。
2.1 Http连接路由
route类型连接的分类
HttpClient将route类型的连接分为简单的(plain)、使用隧道包装的(tunneled)、分层的(layer)连接。在tunnel connection 中使用的多个中间代理被称为代理链。
- plian route是通过直接和目标主机或是代理(和第一个也是唯一的一个代理)建立起来的;
- tunnelled route 是通过和第一个代理通信,消息通过代理链进行传输(Tunnelled routes are established by connecting to the first and tunnelling through a chain of proxies to the target.);如果不存在代理,则无法tunnelled( 隧道化包装?)
- Layered routes是指在已有的连接之上,在封装一层协议( Layered routes are established by layering a protocol over an existing connection. Protocols can only be layered over a tunnel to the target, or over a direct connection without proxies.)(常用的是ssl/tls