HTTP applications sometimes want to encode content before sending it. For example, a server might compress a large HTML document before sending it to a client that is connected over a slow connection, to help lessen the time it takes to transmit the entity. A server might scramble or encrypt the contents in a way that prevents unauthorized third parties from viewing the contents of the document.
These types of encodings are applied to the content at the sender. Once the content is content-encoded, the encoded data is sent to the receiver in the entity body as usual.
The content-encoding process is:
A web server generates an original response message, with original Content-Type and Content-Length headers.
A content-encoding server (perhaps the origin server or a downstream proxy) creates an encoded message. The encoded message has the same Content-Type but (if, for example, the body is compressed) a different Content-Length. The content-encoding server adds a Content-Encoding header to the encoded message, so that a receiving application can decode it.
A receiving program gets the encoded message, decodes it, and obtains the original.
Figure 15-3 sketches a content-encoding example.
Figure 15-3. Content-encoding example
Here, an HTML page is encoded by a gzip content-encoding function, to produce a smaller, compressed body. The compressed body ...