Web服务器 - 当我应该用块传输编码? [英] Web server - when should I use chunked transfer encoding?

查看:183
本文介绍了Web服务器 - 当我应该用块传输编码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

综观各种web服务器的HTTP标头,我注意到有Google.com:

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

client-transfer-encoding: "chunked"

什么是chuncked传输编码,并且我应该使用它我的Web服务器上?

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

推荐答案

分块可用于发送多个部分的HTTP请求或响应,并发送一个部分,而后续部分将不可用。

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

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

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-Length header, 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-Length header if it doesn't know the length of the full response in advance? The solution is to use chunked instead of Content-Length.

阿帕奇(1.3和2),默认情况下,将静态文件的分块的,只要它是有道理的(和HTTP客户端支持的话)。您不必采取任何行动。如果你写你自己的Web应用程序,你可能会考虑生成手工分块响应。

Apache (1.3 and 2), by default, sends static files as chunked whenever 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.

请参阅 http://www.research.att.com/~bala /papers/h0vh1.html http://developers.sun.com /移动/ MIDP /问题/分块/ 多一点。

这篇关于Web服务器 - 当我应该用块传输编码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆