Apache-Compress
view release on metacpan or search on metacpan
Compress.pm view on Meta::CPAN
return OK;
}
sub can_gzip {
my $r = shift;
my $how_decide = $r->dir_config('CompressDecision');
if (!defined($how_decide) || lc($how_decide) eq 'header') {
return +($r->header_in('Accept-Encoding')||'') =~ /gzip/;
} elsif (lc($how_decide) eq 'user-agent') {
return guess_by_user_agent($r->header_in('User-Agent'));
}
die "Unrecognized value '$how_decide' specified for CompressDecision";
}
sub guess_by_user_agent {
# This comes from Andreas' Apache::GzipChain. It's very out of
# date, though, I'd like it if someone sent me a better regex.
my $ua = shift;
return $ua =~ m{
^Mozilla/ # They all start with Mozilla...
\d+\.\d+ # Version string
[\s\[\]\w\-]+ # Language
(?:
\(X11 # Any unix browser should work
Compress.pm view on Meta::CPAN
gzip-compressed data. Certain browsers (Netscape, IE) can request
content compression via the C<Accept-Encoding> header. This can
speed things up if you're sending large files to your users through
slow connections.
Browsers that don't request gzipped data will receive regular
noncompressed data.
Apparently some older browsers (and maybe even some newer ones)
actually support gzip encoding, but don't send the C<Accept-Encoding>
header. If you want to try to guess which browsers these are and
encode the content anyway, you can set the C<CompressDecision>
variable to C<User-Agent>. The default C<CompressDecision> value is
C<Header>, which means it will only look at the incoming
C<Accept-Encoding> header.
Note that the browser-guessing is currently using a regular expression
that I don't think is very good, but I don't know what user agents to
support and which not to. Please send me information if you have any,
especially in the form of a patch. =)
This module is compatibile with Apache::Filter, so you can compress
the output of other content-generators.
=head1 TO DO
Compress::Zlib provides a facility for buffering output until there's
( run in 0.743 second using v1.01-cache-2.11-cpan-702932259ff )