gpt4 book ai didi

http - RFC 2616 HTTP 内容长度和传输编码兼容性

转载 作者:IT王子 更新时间:2023-10-29 01:56:42 25 4
gpt4 key购买 nike

RFC 2616声明如果存在 Transfer-Encoding,则不得发送 Content-Length header 。

The Content-Length header field MUST NOT be sent if these two lengths are different (i.e., if a Transfer-Encoding header field is present).

但是,如果收到两个 header ,客户端应忽略 Content-Length

If a message is received with both a Transfer-Encoding header field and a Content-Length header field, the latter MUST be ignored.

我的解释是否正确,即客户端应该将两个 header 都存在的情况视为正确的 HTTP 响应?还是该条款具体实现?

我问是因为当这种情况发生时,Go 标准 net/http 包会返回错误。

最佳答案

标准并没有真正指定在这种情况下应该发生什么,只是如果消息被接受那么 Content-length 应该被忽略。引用自 RFC 7230 :

If a message is received with both a Transfer-Encoding and aContent-Length header field, the Transfer-Encoding overrides theContent-Length. Such a message might indicate an attempt toperform request smuggling (Section 9.5) or response splitting(Section 9.4) and ought to be handled as an error.

请注意这里的弱“应该”,它与 MUST 相去甚远。但至少 net/http 是完全正确的,因为这种响应是错误的,可以作为错误处理。但它不需要被视为错误

实际上所有浏览器似乎都接受这样的响应并且通常会忽略 Content-length header 。但我在过去也看到过 MS Edge 的一个行为,它正确地将响应主体视为分 block 但另外使用了 Content-length 并忽略了响应主体中未被 内容长度

关于http - RFC 2616 HTTP 内容长度和传输编码兼容性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53001960/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com