On 6/5/06, Philip M. Gollucci <[EMAIL PROTECTED]> wrote:
> I've defined a PerlAccessHandler which needs access to POST body. I've
> implemented a sub read_post {} which uses bucket brigades API to read
> the body (taken from mod_perl2 docs) and returns the data. However,
> the POST body is gone after I read it.
Can you show some code ?
Here is the code that describes the problem.
$ cat httpd.conf | grep PerlAccessHandler
PerlAccessHandler input
$ echo -n 'modperl=1' | POST http://127.0.0.1/post.html
$ grep 'got:' error_log
got: modperl=1
got: undef
sub input {
my $r = shift;
# get the POST body the first time
my $data = read_post($r) || "undef";
print STDERR "got: $data\n";
# get the POST body the second time
$data = read_post($r) || "undef";
print STDERR "got: $data\n";
return Apache2::Const::OK;
}
sub read_post_body {
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::NONBLOCK_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;
}