I'm trying to create a HttpModule that changes the Response.Filter
like so
(for this demonstration just set the filter back to itself):
public class ContentTrafficMonitor : IHttpModule
{
public void Init( HttpApplication context )
{
context.BeginRequest += OnBeginRequest;
}
public void Dispose()
{
}
private static void OnBeginRequest( object sender, EventArgs e )
{
var application = (HttpApplication) sender;
application.Response.Filter = application.Response.Filter;
}
}
Doing so sets the transfer encoding of the response to chunked, rather than using the Content-Length
header.
If I remove the line where the Response.Filter
is set, the response does have the Content-Length
header. Our application depends on the Content-Length
header, is there any way to prevent this behavior?
My guess is, setting the filter interferes with the normal buffering of the output, hence the output is now chunked.
Maybe you could imitate the behaviour by having your filter read till end, ie get all the output & set the content length header based on what you've read before you write everything read out.
It's only a guess though I'm afraid.
Simon