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的连接创建断开额外开销,减轻服务器负载,减少响应时间

相关推荐
AI科技星3 分钟前
数术工坊・八卷全书(番外・实战升华副卷)【终极典藏定稿|完整无删减】
c语言·开发语言·网络·量子计算·agi
DreamLife☼4 分钟前
OpenBCI-脑电信号的隐私与安全保护
网络·安全·开源硬件·脑机接口·eeg·openbci·神经科技
yyuuuzz5 分钟前
云服务器软件部署的几个常见问题
运维·服务器·开发语言·网络·云计算·php·apache
dust_and_stars7 分钟前
为什么ubuntu24 snap install code-server 不需要--classic?
网络·数据库
tiancaijiben18 分钟前
阿里云日志服务SLS全流程对接与深度使用指南
网络·数据库
软件工程小施同学19 分钟前
CCF A区块链论文分享-NDSS 2026(2)-CtPhishCapture:揭露针对加密货币钱包的基于凭证窃取的网络钓鱼诈骗(附pdf)
网络·pdf·区块链
aixingkong92130 分钟前
NVIDIA CPU 特性演进解析
网络
学途路漫漫1 小时前
Ubuntu 24.04 国内网络环境全面优化指南
linux·网络·ubuntu
我是一颗柠檬1 小时前
【计算机网络全面教学】网络层与IP协议,子网划分到路由协议全掌握Day3(2026年)
网络协议·tcp/ip·计算机网络
meilindehuzi_a1 小时前
深入理解 Ajax 异步请求:从 XMLHttpRequest 到 Node.js HTTP 服务实践
http·ajax·node.js