HTTP协议1.1请求头和keep-alive

请求头分类

End-to-end(端对端)

必须全部带给目标服务器,不会被中途变化或去掉

Hop-by-hop(逐跳头)

比如客户端发请求,要路过代理(例如Nginx),头可以被自动删掉,来到真正服务器上是没有的

进入HTTP文档RFC 2616: Hypertext Transfer Protocol -- HTTP/1.1 (rfc-editor.org)

原文:

复制代码
13.5.1 End-to-end and Hop-by-hop Headers
   For the purpose of defining the behavior of caches and non-caching
   proxies, we divide HTTP headers into two categories:
      - End-to-end headers, which are  transmitted to the ultimate
        recipient of a request or response. End-to-end headers in
        responses MUST be stored as part of a cache entry and MUST be
        transmitted in any response formed from a cache entry.

      - Hop-by-hop headers, which are meaningful only for a single
        transport-level connection, and are not stored by caches or
        forwarded by proxies.
   The following HTTP/1.1 headers are hop-by-hop headers:
      - Connection
      - Keep-Alive
      - Proxy-Authenticate
      - Proxy-Authorization
      - TE
      - Trailers
      - Transfer-Encoding
      - Upgrade
   All other headers defined by HTTP/1.1 are end-to-end headers.
   Other hop-by-hop headers MUST be listed in a Connection header,
   (section 14.10) to be introduced into HTTP/1.1 (or later).

上文说以下都是Hop-by-hop头,除了这些都是End-to-end:

  • Connection

  • Keep-Alive

  • Proxy-Authenticate

  • Proxy-Authorization

  • TE

  • Trailers

  • Transfer-Encoding

  • Upgrade

总结:

端到端(End-to-end)

一定会被最终目标接收,必须保存在由缓存生成的响应中,头必须被转发

逐跳头(Hop-by-hop)

只对单次转发有效,会因通过缓存或代理而不再转发

HTTP/1.1和以后版本中如果要使用Hop-to-hop头,需提供Connection头字段

Connection:keep-alive头的作用

这种情况,客户端(浏览器)与Nginx服务器(代理服务器)建立keep-alive连接,不会与Tomcat建立keep-alive

如果是直接访问的Tomcat服务器,则会与tomcat建立keep-alive关系

客户端与服务端的连接保活技术,可以减少TCP的连接创建断开额外开销,减轻服务器负载,减少响应时间

相关推荐
liyuanchao_blog29 分钟前
OVN/OVS场景下虚拟机新网卡通过 DHCP 获取 IP 地址的完整过程
网络·网络协议·tcp/ip·云计算
今天AI了吗1 小时前
DeepSeek Harness 深度解析:从评测架构到实战落地
java·网络·数据库·人工智能·架构·java-ee
M哥支付1 小时前
高频交易优选方案:银联快捷支付通道
服务器·网络·其他·微信·金融
爱倒腾的老唐1 小时前
11、误码率测试仪
网络
逍遥~1422 小时前
什么是工业级算力?算盘科技的核心能力解析
网络·人工智能·科技
稳联技术老娜2 小时前
伺服内嵌EtherNet IP方案:嵌入式小板SPI通讯固件Demo程序适配改造
运维·服务器·网络
uoKent3 小时前
计网中的TCP/UDP协议 特点与联系
网络协议·tcp/ip·udp
CLK音视频广播设备3 小时前
河南川利卡科技集团圆满落地安徽宿州校园网络广播项目
网络·科技
M哥支付5 小时前
快捷支付 VS 网关支付 安全对比
服务器·网络·其他·微信·金融
星恒讯工业路由器5 小时前
房车旅居不“断网”:移动生活如何实现全程在线?
网络·物联网·生活·工业路由器·车载工业路由器·房车通信·双卡备份