perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Javier Alonso Sánchez <javianda...@gmail.com>
Subject Proxy and Trans Handler
Date Thu, 04 Aug 2005 23:26:30 GMT
Hi again.

I'd like to use Proxy Reserve configuration for certain POSTs, so
trans handler seems a good way to change the header before Proxy
phase. Any POSTs would continue their way to the Proxy directive
whithout header changes, and others would change their header and
wouldnt go to the Proxy.

But, how can i do that ?
Any suggestions ?

I have made the next PerTransHandler, but the body doesn't arrive to
the target uri.

package MyApache2::HeaderParser;

 use strict;
 use warnings;

 use Apache2::RequestRec ();
 use Apache2::RequestIO ();
 use Apache2::RequestUtil ();
 use Apache2::ServerUtil ();
 use Apache2::ServerRec ();
 use Apache2::Process ();
 use Apache2::Connection ();
 use Apache2::Filter ();
 use APR::Table ();

 use Apache2::Const -compile => qw(DECLINED OK);

 use constant METHOD        => 'POST';

 sub handler {
       my $r = shift;

       return Apache2::Const::DECLINED unless $r->method eq METHOD;

       #my $content = content($r);

       my $content = $r->content();
       warn("content: $content\n");
       if (0)  {
               my $newuri = '/~jasanchez/test/';
               $r->uri($newuri);
       }


       return Apache2::Const::DECLINED;
       #return Apache2::Const::OK;
}


 use APR::Brigade ();
 use APR::Bucket ();

 use Apache2::Const -compile => qw(MODE_READBYTES);
 use APR::Const    -compile => qw(SUCCESS BLOCK_READ);

 use constant IOBUFSIZE => 8192;

 sub content {
     my $r = shift;

     my $bb = APR::Brigade->new($r->pool, $r->connection->bucket_alloc);

     my $data = '';
     my $seen_eos = 0;
     do {
         $r->input_filters->get_brigade($bb, Apache2::Const::MODE_READBYTES,
                                        APR::Const::BLOCK_READ, IOBUFSIZE);

         for (my $b = $bb->first; $b; $b = $bb->next($b)) {
             if ($b->is_eos) {
                 $seen_eos++;
                 last;
             }

             if ($b->read(my $buf)) {
                 $data .= $buf;
             }

             $b->remove; # optimization to reuse memory
         }
     } while (!$seen_eos);

     $bb->destroy;
     return $data;
 }

 1;


The body content after is EMPTY.

Thanks

Mime
View raw message