views:

96

answers:

1

I'm tring to implement what Steve Souders discusses http://www.stevesouders.com/blog/2010/07/12/velocity-forcing-gzip-compression/ about forcing gzip compression

I've got a module that's running this:

void context_PreSendRequestHeaders(object sender, EventArgs e)
{
    var app = sender as HttpApplication;

    var request = app.Request;
    var response = app.Response;

    if (CompressionUtils.GzipSupported(request) || CompressionUtils.GzipNotSupportedExplicitly(request)) 
    {
        return;
    }

    if (CompressionUtils.GzipSupportedExplicitly(request))
    {
        response.Filter = new GZipStream(response.Filter, CompressionMode.Compress);
        response.AddHeader(HttpHeaderKey.ContentEncoding, "gzip");
        return;
    }

    response.Write("<iframe style=\"display:none;\" src=\"/CompressedPage.aspx\"></iframe>");
}

CompressionUtils.GzipSupported just checks for the 'accepts-encoding' header while CompressionUtils.GzipSupportedExplicitly and CompressionUtils.GzipNotSupportedExplicitly check for the cookie saying whether the browser really can read gzip

But when I load a page in Firefox I get this error:

Content Encoding Error

The page you are trying to view cannot be shown because it uses an invalid or unsupported form of compression.

and in Fiddler it shows that the content-encoding header has been added but the content hasn't been compressed

A: 

So it turns out I was just binding too late, bound to PostMapRequestHandler instead of PreSendRequestHeaders. Working fine now.

Glenn Slaven