6

http头部字段:hop-by-hop headers vs end-to-end headers

 2 years ago
source link: https://segmentfault.com/a/1190000040300453
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

http头部字段:hop-by-hop headers vs end-to-end headers

发布于 52 分钟前

在看RFC文档的时候,看到hop-by-hop这个词,有点疑惑,所以挖掘了下它的相关含义。

hop是跳,hop-by-hop是逐跳的意思。end-to-end则是端到端。这两者都是http的头部字段。

1、含义原文

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 must be 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 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
Public
Proxy-Authenticate
Transfer-Encoding
Upgrade
All other headers defined by HTTP/1.1 are end-to-end headers.
Hop-by-hop headers introduced in future versions of HTTP MUST be listed in a Connection header, as described in section 14.10.
来源:https://www.freesoft.org/CIE/...

[翻译]13.5.1 端到端和逐跳报头

为了定义缓存和非缓存代理的行为,我们将 HTTP 标头分为两类:
End-to-end headers,必须传输到请求或响应的最终接收者。响应中的端到端标头必须作为缓存条目的一部分存储,并在从缓存条目形成的任何响应中传输。
Hop-by-hop headers,仅对单个传输级连接有意义,不由缓存存储或由代理转发。
以下 HTTP/1.1 标头是逐跳标头:
Connection
Keep-Alive
Public
Proxy-Authenticate
Transfer-Encoding
Upgrade
HTTP/1.1 定义的所有其他标头都是端到端标头。
如第 14.10 节所述,在未来版本的 HTTP 中引入的逐跳标头必须列在连接标头中。

三、http连接和tcp连接的区别

一个http连接来回可以包括多个端。比如浏览器发起的请求,先到达服务器宿主机的nginx,然后到达docker容器的nginx(真正的web服务器)。
end-to-end的头部会被中间的代理照样转发。比如请求头的host字段,一般会原封不动的传递到容器的nginx。
而hop-by-bop的头部仅在当前tcp连接中生效。也就是只在浏览器到宿主机nginx之间生效,如果宿主机和容器的nginx没设置,则不会生效。
也就是说,即使浏览器的请求携带了connection: keep-alive,也只表示浏览器到宿主机的nginx之间的长连接,但宿主机nginx到容器nginx是否是长连接,则需要具体分析了。

参考链接:
https://datatracker.ietf.org/...
https://cloud.tencent.com/dev...


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK