Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check programatically whether web server has http compression enabled?

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?

like image 350
Sun Avatar asked Feb 27 '09 02:02

Sun


1 Answers

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

like image 148
Brian R. Bondy Avatar answered Nov 07 '22 22:11

Brian R. Bondy