views:

1278

answers:

3

I want to check whether web server has http compression enabled, and a particular compression (i.e. Gzip, Deflate, Compress) is enabled?

Or If I request data through WebClient Object in .net by setting Accept-Encoding to "gzip, deflate" how can I know whether the retrieved data is compressed before I process it?

+5  A: 

To check what the encoding of the response body is, you should check the HTTP response header: Content-Encoding.

The server is only allowed to use encodings that are specified by the request header accept-encoding. If the server cannot give a response using one of the specified accept-encodings, then it must respond with 406 (Not Acceptable).

Example request:

GET / HTTP/1.1
Host: www.brianbondy.com
Accept-Encoding: gzip,deflate

Example response:

HTTP/1.1 200 OK
Date: Thu, 04 Dec 2003 16:15:12 GMT
Server: Apache/2.0
Content-Encoding: gzip
Content-Length: 1533

Other examples of Accept-Encoding:

 Accept-Encoding: compress, gzip
 Accept-Encoding:
 Accept-Encoding: *
 Accept-Encoding: compress;q=0.5, gzip;q=1.0
 Accept-Encoding: gzip;q=1.0, identity; q=0.5, *;q=0

How to KNOW exactly what encodings are available on the server:

There is no way to know exactly what encodings are available at the server level, because some servers may support certain encodings only for certain file types.

That means that the best you can do is answer the question: For the file specified in the first line of the request, is the specific encoding available for this file? You can answer this by explicitly denying the identity content-encoding and specifying also the encoding you want to know about.

Accept-Encoding: gzip; identity;q=0

Source of examples, HTTP RFC

Brian R. Bondy
But the identity encoding (i.e. no compression) is always allowed, unless you explicitly forbid it. So if the server returns Content-Encoding: identity, you still don't know whether it supports compression or not; it might just have chosen not to compress this particular response.
Thomas
updated description
Brian R. Bondy
+3  A: 

From the HTTP spec:

4. The "identity" content-coding is always acceptable, unless specifically refused because the Accept-Encoding field includes "identity;q=0", or because the field includes "*;q=0" and does not explicitly include the "identity" content-coding. If the Accept-Encoding field-value is empty, then only the "identity" encoding is acceptable.

So if you set Accept-Encoding: identity;q=0, gzip, deflate you force the server to compress it, or return a 406 (Not Acceptable).

Thomas
A: 

It might help.

http://www.whatsmyip.org/http%5Fcompression/

Murat Yasar