You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Reif Peter <ga...@adv.magwien.gv.at> on 2007/06/11 11:50:55 UTC
Reading post-data
In
http://perl.apache.org/docs/2.0/user/porting/compat.html
I read:
if one wishes to simply read POST data, there is the more modern filter
API, along with continued support for read(STDIN, ...) and
$r->read($buf, $r->headers_in->{'content-length'})
But there are two problems with
$r->read($buf, $r->headers_in->{'content-length'}
1. An input filter can change the length of the incoming content. It can
be longer than before, but the content-length header will not be
changed, so some data will be missing.
2. If the POST data are sent per chunked encoding, there is no
content-length header at all.
Unfortunately you cannot tell $r->read to read just all of the data, you
must provide a length.
How do I solve this problems.
Peter
AW: Reading post-data
Posted by Reif Peter <ga...@adv.magwien.gv.at>.
> Reif Peter wrote:
> > Unfortunately you cannot tell $r->read to read just all of
> the data, you
> > must provide a length.
> >
> > How do I solve this problems.
>
> $r->read will return 0 when no more data is available. I have
> been using
> the following simple code with success:
>
> my $postdata = "";
> while ($r->read(my $buf, 8192)) { $postdata .= $buf; }
>
> You should ofcourse select a read-buffer size that will best
> suite your
> setup. I do not know what would be the most optimal setting here.
>
Yes, this code works and I am using it, too. But the documentation says,
you can use
$r->read($buf, $r->headers_in->{'content-length'}
http://perl.apache.org/docs/2.0/user/porting/compat.html
I want to know if the documentation is wrong, and if it is wrong, it
should be corrected!
Peter
Re: Reading post-data
Posted by "Jani M." <mo...@iki.fi>.
Reif Peter wrote:
> Unfortunately you cannot tell $r->read to read just all of the data, you
> must provide a length.
>
> How do I solve this problems.
$r->read will return 0 when no more data is available. I have been using
the following simple code with success:
my $postdata = "";
while ($r->read(my $buf, 8192)) { $postdata .= $buf; }
You should ofcourse select a read-buffer size that will best suite your
setup. I do not know what would be the most optimal setting here.
Cheers,
-- Jani