Web server - when should I use chunked transfer encoding?

筅森魡賤 提交于 2019-12-05 09:37:36

问题


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

client-transfer-encoding: "chunked"

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


回答1:


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

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.

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.

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



来源:https://stackoverflow.com/questions/842197/web-server-when-should-i-use-chunked-transfer-encoding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!