On 8/3/05, Stas Bekman <[EMAIL PROTECTED]> wrote:> 
> 
> I think you are much better off not to use a filter here. Use
> Apache::Request which can give the same POST body more 
> than once. So I'd
> write a trans hander, grabs the body, rewrites the headers based on
> the body and the content handler can still get the body (this is only
> available in libapreq2)
> 

Thanks for the quick response :)

A new question about Apache::Request.
In according to the documentation:

"The Apache2::Request module provides methods for parsing GET and POST
parameters encoded with either application/x-www-form-urlencoded or
multipart/form-data."

Does only work with these two body types?
Is there another way to get the body content and the headers at the same time?

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 uri's.


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;

Reply via email to