</summary>
<seealso><a href="../filter.html">Filters</a></seealso>
+<section id="supportedencodings"><title>Supported Encodings</title>
+ <p>The <code>gzip</code> encoding is the only one supported to ensure complete compatibility
+ with old browser implementations. The <code>deflate</code> encoding is not supported,
+ please check the <a href="http://www.gzip.org/zlib/zlib_faq.html#faq38">zlib's documentation</a>
+ for a complete explanation.
+ </p>
+</section>
+
<section id="recommended"><title>Sample Configurations</title>
<note type="warning"><title>Compression and TLS</title>
<p>Some web applications are vulnerable to an information disclosure
<highlight language="config">
SetOutputFilter DEFLATE
-SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip
+SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip
</highlight>
<p>If you want to restrict the compression to particular MIME types
filters like PHP or SSI. It never touches internal subrequests.
</note>
<note><title>Note</title>
- There is a environment variable <code>force-gzip</code>,
+ There is an environment variable <code>force-gzip</code>,
set via <directive module="mod_env">SetEnv</directive>, which
will ignore the accept-encoding setting of your browser and will
send compressed output.
<p>The <module>mod_deflate</module> module also provides a filter for
inflating/uncompressing a gzip compressed response body. In order to activate
this feature you have to insert the <code>INFLATE</code> filter into
- the outputfilter chain using <directive module="core"
+ the output filter chain using <directive module="core"
>SetOutputFilter</directive> or <directive module="mod_mime"
>AddOutputFilter</directive>, for example:</p>
<highlight language="config">
-<Location /dav-area>
- ProxyPass http://example.com/
+<Location "/dav-area">
+ ProxyPass "http://example.com/"
SetOutputFilter INFLATE
</Location>
</highlight>
>AddInputFilter</directive>, for example:</p>
<highlight language="config">
-<Location /dav-area>
+<Location "/dav-area">
SetInputFilter DEFLATE
</Location>
</highlight>
</example>
</section>
+<section id="precompressed"><title>Serving pre-compressed
+content</title>
+
+ <p>Since <module>mod_deflate</module> re-compresses content each
+ time a request is made, some performance benefit can be derived by
+ pre-compressing the content and telling mod_deflate to serve them
+ without re-compressing them. This may be accomplished using a
+ configuration like the following:</p>
+
+ <highlight language="config">
+<IfModule mod_headers.c>
+ # Serve gzip compressed CSS files if they exist
+ # and the client accepts gzip.
+ RewriteCond "%{HTTP:Accept-encoding}" "gzip"
+ RewriteCond "%{REQUEST_FILENAME}\.gz" "-s"
+ RewriteRule "^(.*)\.css" "$1\.css\.gz" [QSA]
+
+ # Serve gzip compressed JS files if they exist
+ # and the client accepts gzip.
+ RewriteCond "%{HTTP:Accept-encoding}" "gzip"
+ RewriteCond "%{REQUEST_FILENAME}\.gz" "-s"
+ RewriteRule "^(.*)\.js" "$1\.js\.gz" [QSA]
+
+
+ # Serve correct content types, and prevent mod_deflate double gzip.
+ RewriteRule "\.css\.gz$" "-" [T=text/css,E=no-gzip:1]
+ RewriteRule "\.js\.gz$" "-" [T=text/javascript,E=no-gzip:1]
+
+
+ <FilesMatch "(\.js\.gz|\.css\.gz)$">
+ # Serve correct encoding type.
+ Header append Content-Encoding gzip
+
+ # Force proxies to cache gzipped &
+ # non-gzipped css/js files separately.
+ Header append Vary Accept-Encoding
+ </FilesMatch>
+</IfModule>
+ </highlight>
+
+</section>
+
<directivesynopsis>
<name>DeflateFilterNote</name>
<description>Places the compression ratio in a note for logging</description>
<example><title>Example</title>
<highlight language="config">
DeflateFilterNote ratio
-
+
LogFormat '"%r" %b (%{ratio}n) "%{User-agent}i"' deflate
- CustomLog logs/deflate_log deflate
+ CustomLog "logs/deflate_log" deflate
</highlight>
</example>
<p>If you want to extract more accurate values from your logs, you
can use the <var>type</var> argument to specify the type of data
- left as note for logging. <var>type</var> can be one of:</p>
+ left as a note for logging. <var>type</var> can be one of:</p>
<dl>
<dt><code>Input</code></dt>
DeflateFilterNote Ratio ratio
LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' deflate
-CustomLog logs/deflate_log deflate
+CustomLog "logs/deflate_log" deflate
</highlight>
</example>
</usage>
<usage>
<p>The <directive>DeflateBufferSize</directive> directive specifies
the size in bytes of the fragments that zlib should compress at one
- time.</p>
+ time. If the compressed response size is bigger than the one specified
+ by this directive then httpd will switch to chunked encoding
+ (HTTP header <code>Transfer-Encoding</code> set to <code>Chunked</code>), with the
+ side effect of not setting any <code>Content-Length</code> HTTP header. This is particularly
+ important when httpd works behind reverse caching proxies or when httpd is configured with
+ <module>mod_cache</module> and <module>mod_cache_disk</module> because
+ HTTP responses without any <code>Content-Length</code> header might not be cached.
+ </p>
</usage>
</directivesynopsis>
how the ETag hader should be altered when a response is compressed.</p>
<dl>
<dt>AddSuffix</dt>
- <dd><p>Append the compression method onto the end of the ETag, causing
- compressed and uncompressed representatins to have unique ETags.
- This has been the default since 2.4.0, but prevents serving
- "HTTP Not Modified" (304) responses to conditional requests for
+ <dd><p>Append the compression method onto the end of the ETag, causing
+ compressed and uncompressed representations to have unique ETags.
+ This has been the default since 2.4.0, but prevents serving
+ "HTTP Not Modified" (304) responses to conditional requests for
compressed content.</p></dd>
<dt>NoChange</dt>
<dd><p>Don't change the ETag on a compressed response. This was the default
prior to 2.4.0, but does not satisfy the HTTP/1.1 property that all
- representations of the same resource have unique ETags </p></dd>
+ representations of the same resource have unique ETags. </p></dd>
<dt>Remove</dt>
- <dd><p>Remove the ETag header from compressed responses. This prevents
- some conditional requests from being possible, but avoids the
+ <dd><p>Remove the ETag header from compressed responses. This prevents
+ some conditional requests from being possible, but avoids the
shortcomings of the preceding options. </p></dd>
</dl>
</usage>
</directivesynopsis>
+<directivesynopsis>
+<name>DeflateInflateLimitRequestBody</name>
+<description>Maximum size of inflated request bodies</description>
+<syntax>DeflateInflateLimitRequestBody<var>value</var></syntax>
+<default>None, but LimitRequestBody applies after deflation</default>
+<contextlist><context>server config</context><context>virtual host</context>
+<context>directory</context><context>.htaccess</context></contextlist>
+<override>All</override>
+<compatibility>2.4.10 and later</compatibility>
-</modulesynopsis>
+<usage>
+ <p>The <directive>DeflateInflateLimitRequestBody</directive> directive
+ specifies the maximum size of an inflated request body. If it is unset,
+ <directive module="core">LimitRequestBody</directive> is applied to the
+ inflated body.</p>
+</usage>
+</directivesynopsis>
+<directivesynopsis>
+<name>DeflateInflateRatioLimit</name>
+<description>Maximum inflation ratio for request bodies</description>
+<syntax>DeflateInflateRatioLimit <var>value</var></syntax>
+<default>200</default>
+<contextlist><context>server config</context><context>virtual host</context>
+<context>directory</context><context>.htaccess</context></contextlist>
+<override>All</override>
+<compatibility>2.4.10 and later</compatibility>
+
+<usage>
+ <p>The <directive>DeflateInflateRatioLimit</directive> directive
+ specifies the maximum ratio of deflated to inflated size of an
+ inflated request body. This ratio is checked as the body is
+ streamed in, and if crossed more than
+ <directive>DeflateInflateRatioBurst</directive> times, the request
+ will be terminated.</p>
+</usage>
+</directivesynopsis>
+
+<directivesynopsis>
+<name>DeflateInflateRatioBurst</name>
+<description>Maximum number of times the inflation ratio for request bodies
+ can be crossed</description>
+<syntax>DeflateInflateRatioBurst <var>value</var></syntax>
+<default>3</default>
+<contextlist><context>server config</context><context>virtual host</context>
+<context>directory</context><context>.htaccess</context></contextlist>
+<override>All</override>
+<compatibility>2.4.10 and later</compatibility>
+
+<usage>
+ <p>The <directive>DeflateInflateRatioBurst</directive> directive
+ specifies the maximum number of times the
+ <directive>DeflateInflateRatioLimit</directive> can be crossed before
+ terminating the request.</p>
+</usage>
+</directivesynopsis>
+
+</modulesynopsis>