Content-Length或Transfer-Encoding在具有正文的响应中是必需的 [英] Is Content-Length or Transfer-Encoding is mandatory in a response when it has body
问题描述
如果响应具有正文/可以具有正文(即状态代码不是204或304),则它应该在响应头中始终具有内容长度或传输编码。在规范中它不是很清楚。
If the response has a body / can have body (i.e status code is not 204 or 304), should it always have either content-length or Transfer-Encoding in the response header. In the spec it is not very clear.
在我的场景中,我有一个没有内容长度或传输编码头的主体,所以curl一直在等待没有块,没有关闭,没有尺寸。假设接近信号结束
而其他客户端(如邮递员)正在获取内容而不会挂起。
In my scenario I have a body without content-length or transfer encoding header, so the curl is keep on waiting no chunk, no close, no size. Assume close to signal end
while other clients (like postman) are getting the content without hanging.
推荐答案
Transfer-Encoding 是HTTP / 1.1的补充。所以,这个版本的协议似乎与此相关。
Transfer-Encoding is a HTTP/1.1 addition. So, that version of the protocol seems relevant here.
它说明了 Content-Length
:
只要在传输之前确定消息的长度,就应该发送它,除非4.4节中的规则禁止这样做。
it SHOULD be sent whenever the message's length can be determined prior to being transferred, unless this is prohibited by the rules in section 4.4.
这清楚地表明不需要发送。
This clearly indicates that it is not required to be sent.
使用 Transfer-Encoding
标准状态:
Transfer-Encoding general-header字段指示已对邮件正文应用了哪种(如果有)转换类型,以便在发件人和收件人之间安全地进行转换。
The Transfer-Encoding general-header field indicates what (if any) type of transformation has been applied to the message body in order to safely transfer it between the sender and the recipient.
如果没有应用传输编码,这允许省略头字段。
This allows for leaving out the header field if no transfer encoding is being applied.
从以下内容可以看出:回复中的两个标题可能会有效丢失。
From this follows: both headers may validly be missing from a response.
在你的情况下卷曲
告诉它它做了什么:它正在等待远程端关闭连接以了解数据已被完全接收。
In your case curl
is telling what it does: It is waiting for the remote side to close the connection for knowing the data has been fully received.
你应该提供您的卷曲标记和来自 -v
的相关通信,以便更深入地了解为什么其他工具可以更好地了解 EOF之前没有更多数据的原因已经遇到过。
You should provide your curl flags and the relevant communications from -v
to allow more insight in why other tools seem to get a better idea on why there is no more data before EOF has been encountered.
这篇关于Content-Length或Transfer-Encoding在具有正文的响应中是必需的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!