Hello,

-- Slava Bizyayev <[EMAIL PROTECTED]> wrote:

> Finally, I'm going to upload the Apache::Dynagzip 0.03 to CPAN by the
> evening of June 4-th. I'm not sure about the quality of my documentation
> yet. 

the documentation looks very complete :-)


Do you provide also an interface as replacement for $r->print("Bla foobar")?
This might be useful for mod_perl applications which want all the control
over the output and no second output handler ...



[from the documentation:]

> This type of compression is applied when the client is recognized as
> being able to decompress gzip format on the fly. In this version the
> decision is under the control of whether the client sends the
> Accept-Encoding: gzip HTTP header, or not. (Please, let me know if you
> have better idea about that...)

The last years I experimented a lot with gzipped output and wrote my own
gzipping output function (but without chunked encoding :-) ). I realized a
lot of bugs with some different browsers under some environments or
situations. I found no remarks according this in your documentation, so
perhaps you missed something? 
(if I missed something, feel free to write ;-) )

So, e.g. I created a website with a big server generated flash movie (with
Flash generator, mod_perl, Postgres; yep, Flash sucks!), and Netscape
doesn't decompress the output, but claims to understand gzip. AARRGH!

Also compressed output does not work on IE, if the request was POSTed (only
tested with older version, I gess 4.0, of IE).


So here is the part out my output function with the gzip stuff:


=item gzip encoding in output

gzip compression is enabled when:
   
   - browser acceps gzip
   - or browser is an Bugscape 4.x on X11 or Mac


but gzip is DISABLED when:

   - method is not GET:
     at least on some versions of IE (4.x), compressed pages didn't work
     together with POST!
     
   - every image/* content type needs no gzip (at least GIF and JPEG ...)
   
   - browser is not "compatible" and Content-Type is not text/html,
     even if browser said that he understand gzip
     At least Bugscape 4.x didn't decompress embedded objects like
     flash movies
   
   - if the flag $out->{nogzip} is true, disable gzip ...


     (AUTHOR: Alvar Freude, [EMAIL PROTECTED], http://alvar.a-blast.org/)
=cut
   
   
                                       # Important: we change output
                                       # according to this headers
   $r->header_out('Vary', 'Accept-Encoding, User-Agent');

                                       # "Cache" this header line ...
   my $encoding = $r->header_in("Accept-Encoding");
   
                                       # Lets Start the if monster ...
                                       
   if (!$out->{nogzip} &&              # only without nogzip-flag
      ($r->method() eq 'GET') &&       # and with GET Method
      ($browser =~ /compatible/i ?     # is it an compatible browser?
         $content_type !~ /^image/ :   #   then compress unless images
         $content_type eq "text/html"  #   else only gzip text/html
      ) &&                             # and understand the browser gzip?
                                       # Version 1: he said yes
      (defined($encoding) && index($encoding, "gzip") >= 0 ||
      ($browser =~ m{                  # version 2:
          ^Mozilla/                    # it is a Mozilla 4.x ...
          \d+                          
          \.
          (\d+)
          [\s\[\]\w\-]+
          (
           \(X11 |                     # On X11
           Macint.+PPC,\sNav           # Or Mac/PPC
          )
         }x && $1 && $1 == 4 && $browser !~ /compatible/i)
         ))
      {
      
      $r->content_encoding('gzip');    # Compress it with GZIP
      ${ $out->{document} } = Compress::Zlib::memGzip($out->{document});
      }
      
                                       # don't forget Content-Length!
                                       # it enables keepalive and disables
                                       # some Netscape bugs
   $r->header_out('Content-Length', length(${ $out->{document} }));
   
   $r->send_http_header;               # Now we can send the headers ...
   
                                       # And the Data, if needed.
   $r->print(${ $out->{document} }) unless $r->header_only;
   $r->rflush();                       # Flush all, so we can do additional
                                       # stuff like mail delivery and all
                                       # data is sent out


Ciao
  Alvar



-- 
// Unterschreiben!      http://www.odem.org/informationsfreiheit/
// Internet am Telefon: http://www.teletrust.info/
// Das freieste Medium? http://www.odem.org/insert_coin/
// Blaster:             http://www.assoziations-blaster.de/

Reply via email to