David Neale
David Neale

Reputation: 17058

If a browser can shows Accept-Encoding of deflate, can it handle .NET gzipped responses?

I'm looking at this method in this HTTPCombiner:

private bool CanGZip(HttpRequest request)
{
    string acceptEncoding = request.Headers["Accept-Encoding"];
    if (!string.IsNullOrEmpty(acceptEncoding) &&
         (acceptEncoding.Contains("gzip") || acceptEncoding.Contains("deflate")))
        return true;
    return false;
}

If this returns true then the response is compressed using a GZipStream. Is this right?

Upvotes: 4

Views: 501

Answers (3)

ajay_whiz
ajay_whiz

Reputation: 17951

Typically most of the browsers understand GZip and Deflate. They tell the server by specifying it in the request header as Accept-Encoding:gzip, deflate. The HTTPCombiner gives preference to GZip. If both the types are present then GZip is given the preference. HttpCombiner will send the content only if the browser requests for Defalte only.

Upvotes: 0

SirViver
SirViver

Reputation: 2441

GZip (which is based on Deflate) and Deflate are two different algorithms, so a request for "deflate" should definitely not return gzipped content.

However, this should be easy to fix, by simply using a GZipStream if the accept header contains "gzip" and a DeflateStream for "deflate".

Both are included in System.IO.Compression, so it's not like you'd have to code your own deflate algorithm or use a third party implementation.

Upvotes: 3

mathieu
mathieu

Reputation: 31192

Those are two different algorithms :

Some code here :

So, according to the protocol, it is not right, as if the browser says "give me the content using deflate", you shouldn't send it back gzipped.

Upvotes: 3

Related Questions