From: André Malo
Compression is implemented by the DEFLATE
- filter. The following directive
- will enable compression for documents in the container where it
- is placed:
Most popular browsers can not handle compression of all content - so you may want to set the 'gzip-only-text/html' note to 1 to only - allow html files to be compressed (see below).
-If you set this to anything but '1' it will be ignored, so you can do - negative matches.
- -Here is an example of enabling compression for the Apache - documentation:
- -For browsers that have problems even with compression of html files,
- use the
This is a sample configuration for the impatient. But please take + the time and read the sections below for a detailed description!
+ +Note, that gzip compression of binary files (e.g. images)
+ usually has only little effect. Therefore in the example above we use
+ an exclusion list of some file types. Alternatively you may use a
+ positive list using
Compression is implemented by the DEFLATE
+ filter. The following directive
+ will enable compression for documents in the container where it
+ is placed:
Some popular browsers cannot handle compression of all content
+ so you may want to set the gzip-only-text/html
note to
+ 1
to only allow html files to be compressed (see
+ below). If you set this to anything but 1
it
+ will be ignored.
If you want to restrict the compression to particular MIME types
+ in general, you may use the
For browsers that have problems even with compression of all file
+ types, use the no-gzip
+ note for that particular browser so that no compression will be
+ performed. You may combine no-gzip
with gzip-only-text/html
to get the best results. In that case
+ the former overrides the latter. Take a look at the following
+ excerpt from the configuration example
+ defined in the section above:
At first we probe for a User-Agent
string that
+ indicates a Netscape Navigator version of 4.x. These versions
+ have some big problems to decompress content types different
+ from text/html
. The versions 4.06, 4.07 and 4.08 have
+ also sometimes problems to decompress html files. Thus, we
+ completely turn off the deflate filter for them.
The third \b
means
+ "word boundary") in the User-Agent
Header and turn off
+ the restrictions defined before.
DEFLATE
filter is always inserted after RESOURCE
+ filters like PHP or SSI. It never touches internal subrequests.
+ The DEFLATE
filter into
+ the input filter chain using
Now if a request contains a Content-Encoding: gzip
+ header, the body will be automatically decompressed. Ordinary
+ browsers usually don't have the ability to gzip e.g. POST
+ request bodies. However, some special applications actually do
+ support request compression, for instance WebDAV clients.
If you evaluate the request body yourself, don't trust
+ the Content-Length
header! For example, a
+ wide-spread code to read the request body in perl is:
Since the Content-Length header reflects the length of the + incoming data from the client and not the byte count of + the decompressed data, you would read too less and cut off the + stream.
+ +Thus, if you want to slurp the whole request body, use for + example:
+ +Since the DEFLATE
output filter actually performs a
+ kind of content negotiation,
+ you should take care of caching proxy servers. In order to prevent a
+ proxy cache from delivering the wrong data (e.g. gzip
+ compressed data to a client which doesn't send an appropriate
+ Accept-Encoding
header), the origin server
+ (i.e. you) has to indicate the negotiation parameters in the
+ Vary
response header.
If the DEFLATE
filter is involved in the request, the
+ following header will be set:
A HTTP compiliant proxy now delivers the cached data to any client,
+ which sends the same Accept-Encoding
header as
+ the client, which did the initial request that was cached.
Fine. But what happens, if you use some special exclusions dependant
+ on, say the User-Agent
header? The proxy server doesn't
+ know anything about your server configuration, thus you have to tell
+ him, what you're doing. You have to use the Vary
header, for
+ example:
would result in the following response header:
+ +If your decision about compression depends on other information
+ than request headers (e.g. HTTP version), you have to set the
+ Vary
header to the value *
. This prevents
+ documents from caching by HTTP compiliant proxies at all.
The
The