2

I am using a webservice as the endpoint for an XHR request, and planning on gzip/deflate compressing the response for compatible browsers.

I am using code based on http://www.dominicpettifer.co.uk/Blog/17/gzip-compress-your-websites-html-css-script-in-code :

string acceptEncoding = 
            context.Request.Headers["Accept-Encoding"];

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

        context.Response.Write(response);

It is possible that at some later date IIS compression may be turned on. Would this break the response?

penguat
  • 1,337
  • 1
  • 13
  • 25

0 Answers0