perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Torsten Foertsch <>
Subject Re: Access to Request Body
Date Tue, 29 Apr 2008 07:21:17 GMT
On Mon 28 Apr 2008, Tim Gustafson wrote:
> I'm writing a mod_perl logging module, and I can't seem to find anywhere in
> the documentation that talks about how I can access the request body
> (basically, the POST data) of a request during the logging phase.  Is this
> not possible?

It is but you'd have to use an input filter. Something like this:

use Apache2::Const -compile=>qw/M_POST OK/;
use APR::Const -compile=>qw/SUCCESS/;
use Apache2::Filter ();
use APR::Bucket ();
use APR::Brigade ();

if( $r->method_number==Apache2::Const::M_POST ) {
  my @content;
  my $cl=0;
  my $rc=$r->add_input_filter( sub {
    my ($f, $bb, $mode, $block, $readbytes) = @_;

    my $rv = $f->next->get_brigade($bb, $mode, $block, $readbytes);
    return $rv unless $rv == APR::Const::SUCCESS;

    for (my $b = $bb->first; $b; $b = $bb->next($b)) {
      $b->read(my $bdata);
      $cl+=length $bdata;
      push @content, $bdata;

    return Apache2::Const::OK;
  } );

Remember this is just an example not production code. For production you'd 
want to put the data chunks into a temporary file / files. This way you'll 
get the request body stripped of all transfer-encoding.


Need professional mod_perl support?
Just hire me:

View raw message