HTTP 传输编码和请求

发布于 2024-07-15 18:11:07 字数 133 浏览 7 评论 0原文

HTTP 规范规定请求允许使用 Transfer-Encoding 标头 - 但如果服务器不理解给定的 Transfer-Encoding,它应该响应什么错误代码。

据我所知,HTTP 标准没有涵盖这种可能性,但也许我只是忽略了它。

the HTTP specification states that the Transfer-Encoding header is allowed for requests - but what error code should a server respond if it doesn't understand that given Transfer-Encoding.

As far as I know the HTTP standard doesn't cover this possibility, but maybe I have just overlooked it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

思念满溢 2024-07-22 18:11:07

未知的传输编码应引发 HTTP 错误 501“未实现”。
至少 Apache 就是这么做的。

另请参阅 http://argray.com/unixfaq/httpd_error_codes.shtml

编辑: 指向相应 RFC 部分的指针: http:// /www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.5.2

An unknown transfer-encoding should raise a HTTP error 501 "NOT IMPLEMENTED".
That's what Apache does, at least.

Also see http://argray.com/unixfaq/httpd_error_codes.shtml

Edit: pointer to the corresponding RFC section: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.5.2

只等公子 2024-07-22 18:11:07

我同意这个问题的答案并不明显,并且已跟进 HTTP 工作组的邮件列表

更新:Björn H. 正确地指出:

RFC 2616 第 3.6 节:

接收到的服务器
带有传输编码的实体主体
不明白应该返回
501(未实现),然后关闭
连接。

所以它确实已经解决了这个问题。

I agree that the answer to this is non-obvious, and have followed up on the HTTP WG's mailing list.

UPDATE: Björn H. rightfully points out:

Section 3.6 of RFC 2616:

A server which receives an
entity-body with a transfer-coding it
does not understand SHOULD return
501 (Unimplemented), and close the
connection.

So it does address this already.

那片花海 2024-07-22 18:11:07

主要是个人意见。

我一直认为 5xx 错误是实际的编程错误,就像有东西摔倒一样。 如果服务器不理解请求,我会说 4xx 错误是更好的响应,因为问题在于请求而不是服务器上的失败进程。 我不确定是哪一个 4xx,但有几个,所以选择一个应该不难。

Mostly a personal opinion.

i always thought 5xx errors were actual programming errors, like something fell over. If a server doesnt understand the request i would say a 4xx error is a better response as the problem is with the request not so a failed process on the server. Im not sure which 4xx but there are a few so selecting one should not be hard.

偏爱你一生 2024-07-22 18:11:07

HTTP 版本的 Transfer-Encoding 请求格式错误。 因此,服务器应响应 400 Bad Request

A request with an invalid Transfer-Encoding for the HTTP version is malformed. Therefore, the server should respond with 400 Bad Request.

楠木可依 2024-07-22 18:11:07

可以说,无法理解分块编码应该是 500 内部服务器错误,而不是 501,因为 RFC-2616 表示服务器必须理解它。

然而,如果服务器选择不接受带有分块主体的请求,并且它想将此归咎于客户端,那么合法的一种方法是411 Length required——因为不能使用 Content - 长度和传输编码同时存在,无论如何都不发送请求是不切实际的。

Arguably failing to understand chunked encoding ought to be a 500 Internal Server Error rather than 501, because RFC-2616 says the server MUST understand it.

However, if a server chooses not to accept requests with chunked bodies, and it wants to blame the client for this, one way to do so legally would be 411 Length Required -- since one must not use Content-Length and Transfer-Encoding at the same time, and it is not practical to send a request without either anyway.

眉黛浅 2024-07-22 18:11:07

RFC 有点不清楚,但恕我直言,它应该是 406 Not Acceptable

The RFC is a bit unclear, but IMHO it should be 406 Not Acceptable.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文