Hi Geoff,

Does the following patch work just as well for you?  I'm trying to keep
using $r->send_fd if at all possible when we're not compressing.

===================================================================
--- Compress.pm 2000/11/05 05:36:46     1.3
+++ Compress.pm 2000/12/20 04:34:35
@@ -34,14 +34,24 @@
   }
   return SERVER_ERROR unless $fh;
   
+  my $buff;
+  unless (defined read($fh, $buff, 300)) {
+    $r->log_error("Can't read from filehandle '$fh': $!");
+    return SERVER_ERROR;
+  }
+
+  return DECLINED unless length $buff;
+  $can_gzip = 0 if eof($fh);
+
   if ($can_gzip) {
     $r->content_encoding('gzip');
     $r->send_http_header;
     local $/;
-    print Compress::Zlib::memGzip(<$fh>);
+    print Compress::Zlib::memGzip($buff . <$fh>);
   } else {
     $r->send_http_header;
-    $r->send_fd($fh);
+    print $buff;
+    $r->send_fd($fh) unless eof($fh);
   }
   
   return OK;
===================================================================

I'll trust the mod_gzip docs that 300 is a reasonable limit.

Thanks for the patch.


[EMAIL PROTECTED] (Geoffrey Young) wrote:
>> From: Geoffrey Young [mailto:[EMAIL PROTECTED]]
>> Sent: Thursday, December 14, 2000 8:34 AM
>> To: 'Ken Williams'
>> Cc: '[EMAIL PROTECTED]'
>> Subject: Apache::Compress patch
>> 
>> 
>> hi ken...
>> 
>> 
>> something has been bugging me in Apache::Compress for a while now - it
>> _always_ tries to compress output.
>> 
>[snip]
>
>whoops on that patch...  it didn't print filtered output that was less than
>300 characters *doh*.  This should do the trick (against Compress.pm
>1.003)...
>
>--Geoff
>
>--- Compress.pm.old     Thu Dec 14 08:22:15 2000
>+++ Compress.pm Mon Dec 18 15:29:26 2000
>@@ -35,10 +35,23 @@
>   return SERVER_ERROR unless $fh;
>   
>   if ($can_gzip) {
>-    $r->content_encoding('gzip');
>-    $r->send_http_header;
>     local $/;
>-    print Compress::Zlib::memGzip(<$fh>);
>+    local $^W;  # length() gives an uninitialized warning. hmmm...
>+    my $file = <$fh>;
>+
>+    my $length = length($file);
>+
>+    return DECLINED unless $length;
>+
>+    if ($length < 300) {
>+      $r->send_http_header;
>+      $r->print($file);
>+    }
>+    else {
>+      $r->content_encoding('gzip');
>+      $r->send_http_header;
>+      print Compress::Zlib::memGzip($file);
>+    }
>   } else {
>     $r->send_http_header;
>     $r->send_fd($fh);
>
>
>

  -------------------                            -------------------
  Ken Williams                             Last Bastion of Euclidity
  [EMAIL PROTECTED]                            The Math Forum

Reply via email to