http - 发送带有 204 无内容响应的 Content-Length 或 Transfer-Encoding 的 HTTP 应用程序是否损坏?

标签 http networking rfc2616

我无法从 RFC 2616 中分辨出来HTTP 客户端是否应接受包含 Content-Length: 0 或 Transfer-Encoding: chunked header 的 204 No Content 响应。这些 header 似乎破坏了一些 HTTP 客户端和代理,它们显然试图读取空的响应主体,但是 the spec reads :

  1. 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选择了这个解释。然而,lighthttpdIBM选择了相反的解释——服务器不应该为禁止有正文的响应包含这些 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/

相关文章:

Java 安卓套接字

networking - 需要端口号才能在防火墙后面设置 Azure 点到站点 VPN

http - http1.1 rfc2616 中引用字符串的确切语法和语义是什么

HTTP: "gzip,deflate"的首选 Accept-Encoding 是什么?

Angular 2 : Retrieving Data with http get request from server using query string

java - 将 cookie 传递给 GET 请求的问题(POST 之后)

ruby-on-rails - POST json 到 Rails 服务器

http - 拦截某些 HTTP 请求的 Firefox 插件

MySQL 客户端/服务器 : TCP response packet with ACK flag but without PSH

http - Flask:使用数组参数实现 HTTP GET