我无法从 RFC 2616 判断 HTTP 客户端是否应该接受 204 No包含 Content-Length: 0 或 Transfer-Encoding: 分块标头的内容响应。 这些标头似乎破坏了一些 HTTP 客户端和代理,它们显然试图读取空响应正文,但是 规范如下:
- 任何“不得”包含消息正文的响应消息(例如
1xx、204 和 304 响应以及
对 HEAD 请求的任何响应)是
总是以第一个空终止
标题字段之后的行,
无论实体标头字段如何
出现在消息中。
对我来说,“无论实体标头字段如何”意味着客户应该容忍这种情况。 Erlang HTTP 库选择了这种解释。 但是,lighthttpd 和 IBM 选择了相反的解释——服务器不应包含这些禁止包含正文的响应标头。
那么,Web 应用程序是否应该从响应中删除这些标头,或者网络基础设施和客户端是否应该容忍 204 无内容、304 未修改等标头?
I can't tell from RFC 2616 whether an HTTP client should accept a 204 No Content response that includes Content-Length: 0 or Transfer-Encoding: chunked headers. These headers seem to break some HTTP clients and proxies, which apparently attempt to read the empty response body, but 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.
To me "regardless of the entity-header fields" implies that clients should tolerate this state of affairs. The Erlang HTTP library chose this interpretation. However, lighthttpd and IBM chose the opposite interpretation -- that the server should not include these headers for responses that are prohibited from having bodies.
So should the web application remove those headers from the response, or should the network infrastructure and clients tolerate those headers on 204 No Content, 304 Not Modified, etc. ?
发布评论
评论(2)
根据 RFC7230(请参阅 https://www.rfc-editor .org/rfc/rfc7230#section-3.3.1)在第 29 页末尾指出:
因此,Web 应用程序不应随响应一起发送这些标头。
According to the RFC7230 (please see https://www.rfc-editor.org/rfc/rfc7230#section-3.3.1) at the end of Page 29 it states:
Therefore the web application should not send those headers with the response.
我无法告诉你什么是正确的,因为我不了解 HTTP 协议的细节。
但是,您必须问自己:
在我看来,在这种情况下应用程序不应该发送这些标头。
I can't tell you what is correct, in that I don't know the HTTP protocol in that detail.
However, you got to ask yourself:
In my opinion, the application should not send those headers in that case.