use APR::Brigade ();
use APR::Bucket ();
use Apache2::Filter ();
use Apache2::RequestRec ();
use Apache2::RequestIO ();
use Apache2::Const -compile => qw(MODE_READBYTES);
use APR::Const -compile => qw(BLOCK_READ);
use constant IOBUFSIZE => 8192;
sub parse_http_params {
my $r = shift; # Apache2::RequestRec object
my %params = ();
my $args = '';
if ($r->method eq "POST") {
my $bb = APR::Brigade->new($r->pool,
$r->connection->bucket_alloc);
my $seen_eos = 0;
do {
$r->input_filters->get_brigade($bb, Apache2::Const::MODE_R
+EADBYTES,
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)) {
$args .= $buf;
}
$b->remove; # optimization to reuse memory
}
} while (!$seen_eos);
$bb->destroy;
} elsif ($r->method eq "GET") {
$args = $r->args;
}
if (length($args) > 0) {
my @rawparams = split /&/, $args;
foreach my $param (@rawparams) {
my @p = split /=/, $param;
$params{$p[0]} = $p[1];
}
}
return %params;
}
|