How to decompress Html pages client side
<p>I have this proxy code taken from this <a href="http://www.codeproject.com/KB/ajax/ajaxproxy.aspx" rel="nofollow">article</a> and created as an HttpHandler</p>

<pre><code>public void ProcessRequest(HttpContext context)
{
        string url = context.Request["url"];
        string contentType = context.Request["type"];

        // no buffering as we want to save memory
        context.Response.Buffer = false;

        // beging getting content
        using (WebClient client = new WebClient())
        { 

            // set content type if specified
            if (!string.IsNullOrEmpty(contentType))
            {
                client.Headers.Add(HttpRequestHeader.ContentType, contentType);
            }

            client.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate");
            client.Headers.Add(HttpRequestHeader.AcceptLanguage, "en-US");
            client.Headers.Add(HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows; U; Windows NT 6.0; " +
               "en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");                
            client.Headers.Add(HttpRequestHeader.Accept, "*/*");

            // get that data
            byte[] data = client.DownloadData(url);

            if (!context.Response.IsClientConnected) return;

            // deliver content type, encoding and length as it
            // is received from the external url
            context.Response.ContentType = client.ResponseHeaders["Content-Type"];

            string contentEncoding = client.ResponseHeaders["Content-Encoding"];
            string contentLength = client.ResponseHeaders["Content-Length"];

            if (!string.IsNullOrEmpty(contentEncoding))
                context.Response.AppendHeader(HttpRequestHeader.ContentEncoding.ToString(), contentEncoding);

            if (!string.IsNullOrEmpty(contentLength))
                context.Response.AppendHeader(HttpRequestHeader.ContentLength.ToString(), contentLength);


            // transmit the exact bytes downloaded
            context.Response.BinaryWrite(data);


    }
}
</code></pre>

<p>I’ve mapped this Http module in IIS7 as a managed hanlder and in my plain Html page I’m using jQuery to call the proxy and put the results in an iframe.</p>

<pre><code>$(document).ready(function() {
    $.ajax({
        type: "GET",
        url: "a.RegularProxy",
        data: { url: 'http://example.org/test.html', type: "text/html" },
        dataType: "html",
        success: function(data) {
            $("iframe").contents().find('html body').html(data.toString());
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            alert(errorThrown);
        }
    });
});
</code></pre>

<p>Everything works fine when the page is nice and simple, however if the page is compressed (gzip, deflate) I need to find a way to <strong>decompress it on the client side</strong> and not within the proxy - the proxy's function is to be as fast as possible.</p>
