You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Geoffrey Young <gy...@laserlink.net> on 2000/12/14 14:33:53 UTC

Apache::Compress patch

hi ken...


something has been bugging me in Apache::Compress for a while now - it
_always_ tries to compress output.

my thought here is that all filters in the pipeline should be able to return
DECLINED and have apache's defaults take over.  unfortunately, Compress
basically only uses the browser compatibility (and some minimal filehandle
checks) to determine its action, which is either to compress or not compress
(but it always involves a print in either case).

The reason this is important is that if there are two (or more) filters in
the pipeline and the all return DECLINED because a file is not found (which
is better than NOT_FOUND because later handlers may deal with the situation
of null input differently) then Compress tries to compress null and you get
a null document back instead of 404.  

also, this comment from mod_gzip has me thinking...

     * Default to 300 bytes as a minimum size requirement for it
     * to even be worth a compression attempt. This works well as a
     * minimum for both GZIP and ZLIB which are both LZ77 based and,
     * as such, always have the potential to actually increase the
     * size of the file.

here's a quick patch that solves both issues (well we count characters
instead of bytes, but it's close enough and 'use bytes' seemed to really
complain about the uninitialized stuff worse than without it)

--- Compress.pm.old     Thu Dec 14 08:22:15 2000
+++ Compress.pm Thu Dec 14 08:21:52 2000
@@ -35,10 +35,13 @@
   return SERVER_ERROR unless $fh;
   
   if ($can_gzip) {
+    local $/;
+    local $^W;  # length() gives an uninitialized warning. hmmm...
+    my $file = <$fh>;
+    return DECLINED unless length($file) > 300;
     $r->content_encoding('gzip');
     $r->send_http_header;
-    local $/;
-    print Compress::Zlib::memGzip(<$fh>);
+    print Compress::Zlib::memGzip($file);
   } else {
     $r->send_http_header;
     $r->send_fd($fh);


BTW, I've been thinking of trying to integrate a perl interface into
mod_gzip (since all the compression code is containted within it and it has
lots of built in intelligence), but since my C is poor I'm at a loss of
where to start (can't use h2xs since it doesn't have a *.h file).  If anyone
is interested in guiding the C challenged...

--Geoff