mod_gzip - serving compressed content by the Apache webserver - Page 2
Author: Michael Schröpl
Compressing HTTP contents using Content-Encoding
For the transmission of web contents between server and client the Hypertext Transfer Protocol (HTTP) is being used.
The communication works the following way:
- The client is sending a request to the server. This requests mainly consists of HTTP headers that describe which data the client wants to receive.
To some degree the client is able to directly influence the data content (like specifying the URL of the requested page); other parts of its request supply the server with additional information about which type of data the client would prefer to receive, if the server has to offer several data variations.
- The server evaluates all available information to decide which data with what kind of attributes were requested and subsequently attempts to serve these data in a form most suitable to the client's request.
This data packet again contains HTTP headers but mainly data - which nevertheless can only be partially interpretable without consideration of the HTTP headers.
The second aspect of determining the desired content is named Content Negotiation in its general form. Delivering compressed page content in the form described here is based on this general principle as well.
HTTP 1.1 defines in chapter 3.5. so-called content encodings that should be supported be each browser compliant to this standard.
For communication between server and client these encodings have the following meaning:
- This client may specify a liste of accepted content encodings in the HTTP header Accept-Encoding:. The special encoding identity (describing an encoding that doesn't change the content) will be used implicitly as default value.
- The server should deliver the content of the requested document using an encoding accepted by this client.
If the server isn't able to do so the it should reject the request with the status code 406 Not Acceptable; nevertheless it may deliver contents not acceptable for this client according to its request (and whose processing might cause unsolvable problems for the Client).
The Apache webserver uses a defensive strategy in this respect: If it cannot serve a page according to the client's requests but has several other variants on offer it dynamically generates a HTML document containing a short description of the situation and links to all documents in question. (This is the case as well if this very document is requested by a browser that accepts none of the languages de und en supported by myself according to its current configuration; I have deliberately not defined a default value to make this problem aware to foreign language readers of these pages.)
If a server serves a file containing an encoding to a client not capable of handling it then this clients might not be able to handle it correctly.