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

相关推荐
LK_071 小时前
【FastAPI】基础篇 01|开始之前:API、HTTP 与 FastAPI 到底是什么
网络协议·http·fastapi
say_fall1 小时前
【Linux网络编程】计算机网络基础:局域网与广域网、OSI七层模型与TCP/IP五层模型、封装解包与MAC/IP地址、端口号与socket编程接口
linux·网络·tcp/ip·计算机网络·信息与通信
阿星_2 小时前
pydio登陆不了分析问题
网络协议·http·https
Joy T2 小时前
Gzip 压缩原理与实践:HTTP 响应压缩、性能收益与工程配置
网络·网络协议·http
叼烟扛炮2 小时前
Linux 学习笔记(五十四):内网穿透实战——用 frp 让外网访问你的私人电脑
linux·服务器·网络·笔记·学习
CodeYp20193 小时前
第3讲:网络命令
linux·网络·命令
承渊政道21 小时前
Linux网络学习【Reactor反应堆模式】
linux·网络·学习·ubuntu·reactor
爱和冰阔落1 天前
【Linux网络】TCP 服务器如何并发处理多个客户端?从 fork、僵尸进程到双重 fork
linux·运维·服务器·网络
严肃小白兔1 天前
Cloudflare 更新 API Token 管理:从最小权限到自动化凭据安全
网络·安全·自动化
Linux-lucky2 天前
45-Linux学习之旅之防火墙与WEB加固
linux·前端·网络·学习·ubuntu