>As far as I know such output doesn't have to be chunked. All you need is >to set Content-length and then just feed your your data in small parts >to stdout flushing it every time. That's at least how works my web-mail >system in C++ when outputting attachments.
It's not required to use chunked transfer, but to know the full size before sending the content, you will have to generate the full content. Sure, if it is some big static thing, you can just ask the filesystem, but if the large stuff is created dynamically, you can't "just set Content-length", because you don't know what to set it to :-) And chunked transfer gives you the nice effect that the browser gets constantly fed data, so the timeouts of proxies or servers won't kick in. Quite handy if the single chunks are complex to create, as sometimes generating a large result into a temp file (to be able to get the content-length) and then sending out the data might trigger the timeout, as it just plain takes too long to generate the temp file. Happened multiple times to me, so I am quite a fan of chunked transfer :-)