views:

809

answers:

1

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  A: 

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.

pts
How does this relate to http 1.1 keep-alives? Are they basicly the same thing, or can a web server send chunked respones even if it doesn't support keep-alives?
Emil H
Chunked can be used without keep-alive, but this doesn't make sense, because chunked without keep-alive doesn't provide any benefit.
pts
pts I don't think thats correct, a chunk needs to be sent in a single connection otherwise there would be no context in what a chunk is in relation two.. imagine a server receiving tons of connections starting with chunks (which are just a hex length, crlf then payload).
meandmycode