apache 为什么 IIS 不支持分块传输编码?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/338624/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why doesn't IIS support chunked transfer encoding?
提问by Graeme Perrow
I am making an HTTP connection to an IIS web server and sending a POST request with the data encoded using Transfer-Encoding: chunked. When I do this, IIS simply closes the connection, with no error message or status code. According to the HTTP 1.1 spec,
我正在与 IIS Web 服务器建立 HTTP 连接,并发送带有使用 Transfer-Encoding: chunked 编码的数据的 POST 请求。当我这样做时,IIS 只是关闭连接,没有错误消息或状态代码。根据HTTP 1.1 规范,
All HTTP/1.1 applications MUST be able to receive and decode the "chunked" transfer-coding
所有 HTTP/1.1 应用程序必须能够接收和解码“分块”传输编码
so I don't understand why it's (a) not handling that encoding and (b) it's not sending back a status code. If I change the request to send the Content-Length rather than Transfer-Encoding, the query succeeds, but that's not always possible.
所以我不明白为什么它 (a) 不处理该编码和 (b) 它不发回状态代码。如果我将请求更改为发送 Content-Length 而不是 Transfer-Encoding,则查询成功,但这并不总是可能的。
When I try the same thing against Apache, I get a "411 Length required" status and a message saying "chunked Transfer-Encoding forbidden".
当我对 Apache 尝试同样的事情时,我得到一个“411 Length required”状态和一条消息,说“chunked Transfer-Encoding forbidden”。
Why do these servers not support this encoding?
为什么这些服务器不支持这种编码?
采纳答案by MarkR
My understanding is that chunked encoding can only be used in a HTTP response. A chunked request body would have the property of being incompatible with a 1.0 server, and in any case, there would be no way of a user-agent knowing that the server was a 1.0 server until it had already sent the request.
我的理解是分块编码只能用于 HTTP 响应。分块的请求主体具有与 1.0 服务器不兼容的特性,并且在任何情况下,用户代理都无法知道服务器是 1.0 服务器,直到它已经发送了请求。
But I agree it's unclear from the documentation.
但我同意文档中不清楚。
回答by rupello
Take a look at your client.
看看你的客户。
Both IIS & Apache support POST requests using chunked transfer-encoding. You can verify this using the curl utility:
IIS 和 Apache 都支持使用分块传输编码的 POST 请求。您可以使用curl 实用程序验证这一点:
curl <upload-url> --form "upfile=@<local_file>" --header "Transfer-Encoding: chunked"
Verify the transfer is chunked using Wireshark
使用Wireshark验证传输是否分块
回答by Hans Henrik
It goes both ways. try uploading a image 2MB++ to photobucket and record it. their uploader uploads chunked to their apache servers.
它是双向的。尝试将 2MB++ 的图像上传到 photobucket 并记录下来。他们的上传者上传分块到他们的 apache 服务器。
回答by Sunny Sharma
This command came to rescue for me!
这个命令是来拯救我的!
C:\Windows\System32\Inetsrv\Appcmd.exe set config -section:httpCompression
-[name='gzip'].staticCompressionLevel:9 -[name='gzip'].dynamicCompressionLevel:4
C:\Windows\System32\Inetsrv\Appcmd.exe 设置配置 -section:httpCompression
-[name='gzip'].staticCompressionLevel:9 -[name='gzip'].dynamicCompressionLevel:4
saved my day... hope it helps someone like me!
拯救了我的一天......希望它可以帮助像我这样的人!
回答by grieve
My only guess is they did not implement it out of concerns for security. In a naive solution it would be easy to set up a DOS attack by starting multiple chunked transfers that never end. And a complex solution which could account for the DOS attack is probably not worth the effort.
我唯一的猜测是他们出于安全考虑没有实施它。在一个简单的解决方案中,很容易通过启动多个永不结束的分块传输来设置 DOS 攻击。一个可以解释 DOS 攻击的复杂解决方案可能不值得付出努力。
Of course I cannot speak for Apache or IIS, you may be able to contact the Apache team directly though: http://httpd.apache.org/bug_report.html
当然我不能代表 Apache 或 IIS,不过你可以直接联系 Apache 团队:http: //httpd.apache.org/bug_report.html
I agree with MarkR that I always thought chunked encoding could only be used as a response, but the documentation sure makes it sound like it can be used in a request or a response.
我同意 MarkR 的观点,我一直认为分块编码只能用作响应,但文档确实使它听起来像是可以在请求或响应中使用。

