Author: Michael Schröpl
Description: A short description of the procedure for serving compressed page content in HTTP
Keywords: Apache, HTTP, encoding, gzip, compression

# Compressing HTTP contents using Content-Encoding

## Communication in HTTP

For the transmission of web contents between server and client the Hypertext Transfer Protocol (HTTP) is being used.

The communication works the following way:

1. 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.
2. 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.

## Encodings in HTTP

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:

1. 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.
2. 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.

(Michael Schröpl, 2002-07-12)