<?xml version="1.0" encoding="iso-8859-1" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Compressing HTTP contents using Content-Encoding</title> <meta name="author" content="Michael Schröpl" /> <meta name="description" content="A short description of the procedure for serving compressed page content in HTTP" /> <meta name="keywords" content="Apache, HTTP, encoding, gzip, compression" /> <style type="text/css"> body{font-family:sans-serif;margin:0px 30px 0px 30px;} h1{font-size:22px;margin-top:20px;} h2{font-size:18px;margin-top:14px;} small{font-size:80%;} td{vertical-align:top;} tt{font-weight:bold;} code,tt{font-family:"Courier New",monospace;} h1,h2{margin-bottom:1px;} p,td{margin-top:3px;margin-bottom:3px;} p,ul,ol,li{font-size:17px;line-height:22px;} ul,ol,li{margin-top:0px;margin-bottom:0px;} img{border-width:0;} #nav{position:absolute;top:30px;left:0px;font-size:14px;width:170px;font-weight:bold;margin:2px 2px 2px 30px;} #nav[id]{position:fixed;} #nav img{margin:5px;} #nav p, #nav a:hover, #nav a{display:block;padding:3px;margin:2px;width:150px;font-size:15px;line-height:18px;} #content{position:absolute;left:220px;right:30px;} #mail{text-align:right;} #icon{width:190px;float:left;} #mail,#icon{margin-top:30px;} @media screen { body{color:#000;background-color:#f8ebd9;} h1{color:#666;} h2{color:#840;} code{color:#333;} em{color:#900;} tt{color:#909;} h1,h2,code,em,tt{background-color:inherit;} .new13192a{color:#inherit;background-color:#ffd;} .new13261a{color:#inherit;background-color:#eff;} .bugfix{color:#fff;background-color:#f00;font-weight:bold;padding:0px 4px;} #nav a{color:#530;background-color:transparent;} #nav a{text-decoration:none;} #nav p, #nav a:hover{color:#000;background-color:#fff;} #nav p {border:1px #660 solid;} #nav a {border:1px #666 dotted;} } @media print { #icon,#nav{display:none;} #content{position:absolute;left:0px;right:0px;} } </style> </head> <body> <div id="nav"> <img src="mod_gzip_logo.gif" height="47" width="102" alt="mod_gzip logo" /> <a title="mod_gzip - what's that, anyway?" href="index.htm">mod_gzip</a> <p>Content-Encoding</p> <a title="Which browsers can handle 'Content-Encoding: gzip'?" href="browser.htm">Browsers</a> <a title="How do Firewalls handle 'Content-Encoding:'?" href="firewalls.htm">Firewalls</a> <a title="An example configuration for mod_gzip" href="config.htm">Configuration</a> <a title="Complete description of mod_gzip status codes" href="status.htm">Status Codes</a> <a title="Possible enhancements in future versions of mod_gzip" href="enhancements.htm">Enhancements</a> <a title="Caching of negotiated HTTP responses" href="cache.htm">Caching</a> <a title="Version history and change log for mod_gzip" href="versions.htm">Versions</a> <a title="Other ressources about mod_gzip" href="links.htm">Links</a> </div> <div id="content"> <h1>Compressing HTTP contents using Content-Encoding</h1> <h2><a id="communication"></a>Communication in HTTP</h2> <p>For the transmission of web contents between server and client the <strong>Hypertext Transfer Protocol</strong> <small>(<a href="http://www.w3.org/Protocols/rfc2616/rfc2616.html"><img class="linkicon" height="15" width="16" alt="arrow" title="external" src="extern.gif" />HTTP</a>)</small> is being used.</p> <p>The communication works the following way:</p> <ol> <li>The client is sending a request to the server. This requests mainly consists of <strong>HTTP headers</strong> that describe which data the client wants to receive.<br /> To some degree the client is able to <em>directly influence</em> the data content <small>(like specifying the URL of the requested page)</small>; other parts of its request supply the server with additional information about which type of data the client would <em>prefer to receive</em>, if the server has to offer several data variations.</li> <li>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.<br /> This data packet again contains HTTP headers but mainly <strong>data</strong> - which nevertheless can only be partially interpretable without consideration of the HTTP headers.</li> </ol> <p>The second aspect of determining the desired content is named <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec12.html#sec12"><img class="linkicon" height="15" width="16" alt="arrow" title="external" src="extern.gif" />Content Negotiation</a> in its general form. Delivering compressed page content in the form described here is based on this general principle as well.</p> <h2><a id="encoding"></a>Encodings in HTTP</h2> <p>HTTP 1.1 defines in <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.5"><img class="linkicon" height="15" width="16" alt="arrow" title="external" src="extern.gif" />chapter 3.5.</a> so-called <strong>content encodings</strong> that should be supported be each browser compliant to this standard.</p> <p>For communication between server and client these encodings have the following meaning:</p> <ol> <li>This client <em>may</em> specify a liste of accepted content encodings in the HTTP header <code>Accept-Encoding:</code>. The special encoding <code>identity</code> <small>(describing an encoding that doesn't change the content)</small> will be used implicitly as default value.</li> <li>The server <em>should</em> deliver the content of the requested document using an encoding accepted by this client.<br /> If the server isn't able to do so the it <em>should</em> reject the request with the <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.7"><img class="linkicon" height="15" width="16" alt="arrow" title="external" src="extern.gif" />status code <code>406 Not Acceptable</code></a>; nevertheless it <em>may</em> deliver contents not acceptable for this client according to its request <small>(and whose processing might cause unsolvable problems for the Client)</small>.<br /> 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. <small>(This is the case as well if this very document is requested by a browser that accepts none of the languages <code>de</code> und <code>en</code> 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.)</small></li> </ol> <p>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.</p> <div id="icon"> <a href="http://validator.w3.org/check/referer"><img alt="" title="valid XHTML 1.1" height="31" width="88" src="valid-xhtml11.png" /></a><a href="http://jigsaw.w3.org/css-validator/check/referer"><img alt="" title="valid CSS" height="31" width="88" src="valid-css.png" /></a> </div> <p id="mail">(<a href="mailto:michael.schroepl@gmx.de?subject=mod_gzip">Michael Schröpl</a>, 2002-07-12)</p> </div> </body> </html>