apache Web 服务器 - 我什么时候应该使用分块传输编码?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/842197/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 17:35:11  来源:igfitidea点击:

Web server - when should I use chunked transfer encoding?

apacheencodingwebserverchunked-encoding

提问by

Looking at various web servers HTTP Headers, I notice that Google.com has:

查看各种网络服务器 HTTP 标头,我注意到 Google.com 有:

client-transfer-encoding: "chunked"

What is chuncked transfer encoding and should I be using it on my web server?

什么是分块传输编码,我应该在我的网络服务器上使用它吗?

回答by pts

Chunked can be used to send a HTTP request or response in multiple parts, and send one part while subsequent parts are not available.

Chunked 可用于发送一个 HTTP 请求或响应的多个部分,并在后续部分不可用时发送一个部分。

Multiple request--response pairs can be transferred over a single HTTP connection. (This is to avoid the overhead of the TCP connect() for subsequent requests.) To implement this, the client needs to know where the server response ends. If the server generates the Content-Lengthheader, the client can count down the bytes. When there are no bytes left to read, the client can initiate the next request. But how would the server generate the Content-Lengthheader if it doesn't know the length of the full response in advance? The solution is to use chunkedinstead of Content-Length.

多个请求-响应对可以通过单个 HTTP 连接传输。(这是为了避免后续请求的 TCP connect() 开销。)要实现这一点,客户端需要知道服务器响应在哪里结束。如果服务器生成Content-Length标头,则客户端可以对字节进行倒计时。当没有剩余字节可供读取时,客户端可以发起下一个请求。但是如果服务器事先不知道完整响应的长度,它将如何生成Content-Length标头?解决方案是使用chunked而不是Content-Length

Apache (1.3 and 2), by default, sends static files as chunkedwhenever it makes sense (and the HTTP client supports it). You don't have to take any action. If you write your own web application, you might consider generating a chunked response by hand.

默认情况下,Apache(1.3 和 2)在有意义的时候(并且 HTTP 客户端支持它)将静态文件作为分块发送。您无需采取任何行动。如果您编写自己的 Web 应用程序,您可能会考虑手动生成分块响应。

See http://www.research.att.com/~bala/papers/h0vh1.htmland http://developers.sun.com/mobility/midp/questions/chunking/for a little more.

更多信息请参见http://www.research.att.com/~bala/papers/h0vh1.htmlhttp://developers.sun.com/mobility/midp/questions/chunking/