HTTP 传输编码和请求
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
未知的传输编码应引发 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
我同意这个问题的答案并不明显,并且已跟进 HTTP 工作组的邮件列表。
更新:Björn H. 正确地指出:
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:
主要是个人意见。
我一直认为 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.
HTTP 版本的
Transfer-Encoding
请求格式错误。 因此,服务器应响应400 Bad Request
。A request with an invalid
Transfer-Encoding
for the HTTP version is malformed. Therefore, the server should respond with400 Bad Request
.可以说,无法理解分块编码应该是 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.
RFC 有点不清楚,但恕我直言,它应该是 406 Not Acceptable。
The RFC is a bit unclear, but IMHO it should be 406 Not Acceptable.