我无法从 RFC 2616 中分辨出来HTTP 客户端是否应接受包含 Content-Length: 0 或 Transfer-Encoding: chunked header 的 204 No Content 响应。这些 header 似乎破坏了一些 HTTP 客户端和代理,它们显然试图读取空的响应主体,但是 the spec reads :
- Any response message which "MUST NOT" include a message-body (such as the 1xx, 204, and 304 responses and any response to a HEAD request) is always terminated by the first empty line after the header fields, regardless of the entity-header fields present in the message.
对我而言,“不管实体 header 字段如何”意味着客户应该容忍这种情况。 Erlang HTTP library选择了这个解释。然而,lighthttpd和 IBM选择了相反的解释——服务器不应该为禁止有正文的响应包含这些 header 。
那么 Web 应用程序是否应该从响应中删除这些 header ,或者网络基础设施和客户端是否应该容忍 204 无内容、304 未修改等 header ?
最佳答案
根据第 29 页末尾的 RFC7230(请参阅 https://www.rfc-editor.org/rfc/rfc7230#section-3.3.1),它指出:
A server MUST NOT send a Transfer-Encoding header field in any response with a status code of 1xx (Informational) or 204 (No Content).
因此,Web 应用程序不应将这些 header 与响应一起发送。
关于http - 发送带有 204 无内容响应的 Content-Length 或 Transfer-Encoding 的 HTTP 应用程序是否损坏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/912863/