Setting Content-Length header for responses too big to buffer

  • Thread starter Thread starter Vlad Hrybok
  • Start date Start date
V

Vlad Hrybok

Hi, all.

I am writing an http handler that sends out lots of large files using
HttpResponse. I found that the only way to set Content-Length header on the
response is to allow the response to get completely buffered, which is
something I need to avoid because it wastes memory and delays data from being
sent. Setting response.Buffer = false; or doing response.Flush(); turns on
chunking and removes the Content-Length header altogether, so the requestor
loses the content length information and does not now how much data to expect.

How can I set the Content-Length header, and yet prevent complete buffering
of the response?

Thank you,
 
you just have to set the content header value before writing any body
content (before calling write).

-- bruce (sqlwork.com)
 
Back
Top