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

相关推荐
一直向钱42 分钟前
基于你的 SRS 直播流煤体配置(通过 http_hooks 回调实现鉴权),结合 TP6 框架,以下是完整的 PHP SDK 封装方案
网络协议·http·php
☆璇1 小时前
【Linux】Reactor反应堆模式
linux·运维·服务器·网络
七七七七071 小时前
【计算机网络】UDP协议深度解析:从报文结构到可靠性设计
服务器·网络·网络协议·计算机网络·算法·udp
CDwenhuohuo1 小时前
WebSocket 前端node启用ws调试
前端·websocket·网络协议
半桔2 小时前
【IO多路转接】epoll 高性能网络编程:从底层机制到服务器实战
linux·运维·服务器·网络·php
come112342 小时前
深入解析抖音和CSDN的推荐逻辑的区别
网络
爱编程的鱼2 小时前
301 是什么意思?——HTTP 状态码详解与应用
网络·网络协议·http
路過的好心人3 小时前
Nginx 的多个场景配置
运维·网络·nginx
-孤存-6 小时前
深入浅出:TCP/UDP协议核心原理
网络·网络协议·tcp/ip·1024程序员节
电鱼智能的电小鱼8 小时前
基于电鱼 AI 工控机的智慧工地视频智能分析方案——边缘端AI检测,实现无人值守下的实时安全预警
网络·人工智能·嵌入式硬件·算法·安全·音视频