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

相关推荐
宁风NF43 分钟前
JavaScript:网络请求与前端通信
开发语言·前端·javascript·网络·学习·ecmascript
孪生质数-1 小时前
AI Agent 工程实践(一):大模型 API 接入示范
网络·人工智能·ai·chatgpt·github·claude·claudecode
雾里0不看花1 小时前
【App Service Linux】在Linux App Service中安装 tcpdump 并抓取网络包
linux·网络·tcpdump
雾里0不看花2 小时前
.NET通过HTTP操作MINIO
http·.net·iphone
深圳市爱派派智能科技有限公司3 小时前
“高通 QCS8550 嵌入式主板 EC-A8550JD4:48 TOPS 算力上板“
网络·嵌入式·边缘计算·高通·qcs8550·天启智能·ec-a8550jd4
妍妍爱学习3 小时前
技术破界 数智共生:华为星河AI网络商业峰会5月18日深圳启幕
网络·ai·生态·数智化·峰会
funnycoffee1233 小时前
Cisco ip access-list序号重排方法
linux·网络·tcp/ip
nvd114 小时前
GCP 4层 外部网络负载均衡器深度解析
运维·网络·负载均衡
AI人工智能+电脑小能手4 小时前
【大白话说Java面试题 第210题】【10_网络协议篇】第1题:说说 TCP/IP 网络五层模型
java·网络协议·tcp/ip·计算机网络·网络五层模型
不在逃避q4 小时前
使用.NET实现自带思考的Tool 并且提供mcp streamable http服务
网络协议·http·.net