Keith Costa
Keith Costa

Reputation: 1793

Regarding httpcompression asp.net

i saw people just detect that requesting browser support http compression or not. if support then detect support gzip or deflate.

and then just add attribute to response object like

HttpContext.Current.Response.AppendHeader("Content-encoding", "gzip");

or

HttpContext.Current.Response.AppendHeader("Content-encoding", "deflate");

i just need to know who actually comresee the response. is it webserver or asp.net worker process. please duscuss in detail who and how compress the response. thanks

Upvotes: 0

Views: 302

Answers (1)

Aristos
Aristos

Reputation: 66641

Actually the header that you show here is not make the compression. What make the compression is a Stream Class that you set on Response.Filter and this compression is made by Asp.Net something like:

    if (acceptEncoding.Contains("gzip"))
    {
        // gzip
        app.Response.Filter = new GZipStream(prevUncompressedStream, CompressionMode.Compress);
        app.Response.AppendHeader("Content-Encoding", "gzip");
    }       
    else if (acceptEncoding.Contains("deflate") || acceptEncoding == "*")
    {
        // deflate
        app.Response.Filter = new DeflateStream(prevUncompressedStream, CompressionMode.Compress);
        app.Response.AppendHeader("Content-Encoding", "deflate");
    }       

If you made this then the compression is done by asp.net and NOT by IIS. The iis then detect that the file is all ready compressed and not compressed again. Some times I have see that this detection fails and the page is not show at all, so in this case you deactivate the iis compression.

Here is the gZipStream Class that is inside asp.net http://msdn.microsoft.com/en-us/library/system.io.compression.gzipstream.aspx

So the asp.net worked process made the compression, if you set the GZipStream, of the DeflateStream

Here is an example of file compression by asp.net using GZipStream http://www.dotnetperls.com/gzipstream

I prefer to make the compression on asp.net and not on iis, because I have more control on it.

Upvotes: 1

Related Questions