Response ContentLength always zero (v2.0)

Jan 20, 2011 at 3:40 PM

I'm using SendingResponse event to track the data sent by the server. It seems that Response.ContentLength is always zero, though the data is sent properly. The same for e.Response.Body.Length. Trying to read e.Context.Stream.Length in the RequestEventArgs e results in an exception.

So, is there any way to get the bytes count of the response?


Feb 7, 2011 at 3:45 PM

Strange. Can you create a small sample project illustrating the problem?

Feb 7, 2011 at 6:06 PM

Have a look at I've used the latest code in the 2.0 trunk.

The log shows

18:51:04.495: Server started, listener running
18:51:04.496: Please open in your favorite browser.
18:51:20.366: SendingResponse: /test.html (0 bytes)
18:51:20.381: SendingResponse: /test.css (0 bytes)
18:51:20.381: SendingResponse: /test.png (0 bytes)

And I found another strange behaviour: In the test app you'll find the lines

server.RequestReceived += new EventHandler<RequestEventArgs>(server_RequestReceived);
//server.PrepareRequest += new EventHandler<RequestEventArgs>(server_PrepareRequest);
server.SendingResponse += new EventHandler<RequestEventArgs>(server_SendingResponse);
server.ErrorPageRequested += new EventHandler<ErrorPageEventArgs>(server_ErrorPageRequested);
If I uncomment the second line, the SendingResponse event won't get fired anymore.