You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axkit-dev@xml.apache.org by ma...@apache.org on 2002/05/21 00:49:35 UTC

cvs commit: xml-axkit/lib/Apache/AxKit Cache.pm

matts       02/05/20 15:49:35

  Modified:    lib      AxKit.pm
               lib/Apache/AxKit Cache.pm
  Log:
  Implemented AxFastPassthru (with default being slow)
  Attempt to fix some of the weird gzip bugs
  
  Revision  Changes    Path
  1.9       +25 -10    xml-axkit/lib/AxKit.pm
  
  Index: AxKit.pm
  ===================================================================
  RCS file: /home/cvs/xml-axkit/lib/AxKit.pm,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- AxKit.pm	13 May 2002 19:33:28 -0000	1.8
  +++ AxKit.pm	20 May 2002 22:49:35 -0000	1.9
  @@ -1,4 +1,4 @@
  -# $Id: AxKit.pm,v 1.8 2002/05/13 19:33:28 kip Exp $
  +# $Id: AxKit.pm,v 1.9 2002/05/20 22:49:35 matts Exp $
   
   package AxKit;
   use strict;
  @@ -17,6 +17,7 @@
   use Apache::AxKit::Provider::Scalar;
   use Apache::AxKit::CharsetConv;
   use File::Basename ();
  +use Compress::Zlib ();
   
   Apache::AxKit::CharsetConv::raise_error(1);
   
  @@ -158,7 +159,7 @@
       my $provider = Apache::AxKit::Provider->new_content_provider($r);
   
       return $provider->decline(reason => "passthru set")
  -            if $r->notes('axkit_passthru');
  +            if ($r->notes('axkit_passthru') && $r->dir_config('AxFastPassthru'));
   
       return main_handler($r, $provider);
   }
  @@ -208,7 +209,7 @@
       my $provider = Apache::AxKit::Provider->new_content_provider($r);
   
       return $provider->decline(reason => "passthru set")
  -            if $r->notes('axkit_passthru');
  +            if ($r->notes('axkit_passthru') && $r->dir_config('AxFastPassthru'));
   
       return main_handler($r, $provider);
   }
  @@ -223,6 +224,20 @@
           return $provider->decline();
       }
   
  +    if ($r->notes('axkit_passthru')) {
  +        # slow passthru
  +        $r->send_http_header;
  +        eval {
  +            my $fh = $provider->get_fh;
  +            $r->send_fd($fh);
  +        };
  +        if ($@) {
  +            my $str = $provider->get_strref;
  +            $r->print($str);
  +        }
  +        return OK;
  +    }
  +
       my $retcode = eval {
           # $r->header_out('X-AxKit-Version', $VERSION);
   
  @@ -507,7 +522,7 @@
           my $mapto = $style->{module};
   
           AxKit::load_module($mapto);
  -        
  +
           AxKit::Debug(3, "about to execute: $mapto\::handler");
   
           my $method = "handler";
  @@ -518,9 +533,9 @@
                           );
               }
               my $retval = $mapto->$method(
  -                    $r, 
  -                    $provider, 
  -                    $styleprovider, 
  +                    $r,
  +                    $provider,
  +                    $styleprovider,
                       !@$styles, # any more left?
                       );
               $result_code = $retval if $retval != OK;
  @@ -670,12 +685,12 @@
               AxKit::Debug(4, 'Sending gzipped xml string to browser');
               AxKit::Apache::send_http_header($r);
               if ($doit) {
  -                $r->print( Compress::Zlib::memGzip(
  +                $r->print( unpack("U0A*", Compress::Zlib::memGzip( 
                            $transformer->( $r->pnotes('xml_string') )
  -                         ) );
  +                         ) ) );
               }
               else {
  -                $r->print( Compress::Zlib::memGzip( $r->pnotes('xml_string') ) );
  +                $r->print( unpack("U0A*", Compress::Zlib::memGzip( $r->pnotes('xml_string') ) ) );
               }
           }
           else {
  
  
  
  1.4       +6 -10     xml-axkit/lib/Apache/AxKit/Cache.pm
  
  Index: Cache.pm
  ===================================================================
  RCS file: /home/cvs/xml-axkit/lib/Apache/AxKit/Cache.pm,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Cache.pm	18 Feb 2002 18:36:20 -0000	1.3
  +++ Cache.pm	20 May 2002 22:49:35 -0000	1.4
  @@ -1,4 +1,4 @@
  -# $Id: Cache.pm,v 1.3 2002/02/18 18:36:20 darobin Exp $
  +# $Id: Cache.pm,v 1.4 2002/05/20 22:49:35 matts Exp $
   
   package Apache::AxKit::Cache;
   use strict;
  @@ -7,7 +7,7 @@
   use Apache::Constants qw(OK DECLINED);
   use Apache::AxKit::Exception;
   use Digest::MD5 ();
  -use Compress::Zlib;
  +use Compress::Zlib qw(gzopen);
   use Fcntl qw(:flock O_RDWR O_WRONLY O_CREAT O_RDONLY);
   
   # use vars qw/$COUNT/;
  @@ -123,14 +123,10 @@
       }
       
       if ($self->{gzip} && $AxKit::Cfg->GzipOutput) {
  -        AxKit::Debug(3, 'Creating gzip output cache');
  -        my $fh = Apache->gensym();
  -        if (sysopen($fh, $self->{file}.'new.gz', O_RDWR|O_CREAT)) {
  -            flock($fh, LOCK_EX);
  -            seek($fh, 0, 0);
  -            truncate($fh, 0);
  -            print $fh ''.Compress::Zlib::memGzip($_[0]);
  -            close $fh;
  +        AxKit::Debug(3, "Creating gzip output cache: $self->{file}.gz");
  +        if (my $gz = gzopen($self->{file}.'new.gz', "wb")) {
  +            $gz->gzwrite($_[0]);
  +            $gz->gzclose();
               rename($self->{file}.'new.gz', $self->{file}.'.gz')
                       || throw Apache::AxKit::Exception::IO( -text => "Couldn't rename gzipped cachefile: $!");
           }