You are viewing a plain text version of this content. The canonical link for it is here.
Posted to apreq-dev@httpd.apache.org by Zbynek Jun <zb...@junix.cz> on 2011/07/20 17:14:38 UTC

post body parsing

Hi,

	i am experiencing problems with parsing urlencoded post body with 
libapreq2/Apache2::Request. It returns bad set of variable/value pairs 
in case of ugly formated post body. For examle:

post body:
a=&a&b=x&b=&b&a=x&c=x

ideal case:
'a' => [ '', '', 'x' ], 'b' => [ 'x', '', ''], 'c' => [ 'x']

from Apache2::Request:
'a' => '', 'b' => '', 'c' => 'x', 'a&b' => 'x', 'b&a' => 'x'

	Post body is properly encoded and posted with Content-Type 
'application/x-www-form-urlencoded; charset=UTF-8' via XMLHttpRequest. 
Server is Apache/2.2.17 (FreeBSD), libapreq2-2.13. Some ideas ? Is it 
possible to get unparsed post body from Apache2::Request ?

TIA

Zbynek Jun

Re: post body parsing

Posted by Zbynek Jun <zb...@junix.cz>.
On 20.7.2011 23:24, Torsten Förtsch wrote:
> On Wednesday, 20 July 2011 17:14:38 Zbynek Jun wrote:
>> post body:
>> a=&a&b=x&b=&b&a=x&c=x
>>
>> ideal case:
>> 'a' =>  [ '', '', 'x' ], 'b' =>  [ 'x', '', ''], 'c' =>  [ 'x']
>
> I'd say the ideal case would be a list:
>
>    'a', '', 'a', undef, 'b', 'x', 'b', undef, 'a', 'x', 'c', 'x'
>
> Anything else drops information. "a=" is not necessarily the same as
> simply "a" and "a=1&b=2&a=3" is not necessarily the same as
> "a=1&a=3&b=2".

Yes right. Difference between a= and a is sweet on the top :)

Anyway post body parser in libapreq2 is broken at least on my config. Is 
it known problem/bug ? I could not find anything relevant in mailinglist 
archive.

Maybe this is the reason why RT is using args_method   => "CGI" instead 
of "mod_perl". Apache1.x with Apache::Request module works flawlessly.


> You can read the request body via the Apache2::RequestRec object if
> Apache2::RequestIO is loaded.
>

Thank you for hint. Now i have robust and correct parser implemented in 
perl, but also have concerns about performance and smooth integration 
with other perl modules.

postbody:
&&&a&b=&a=4&a=1&t=&d&d&d=&d&b=x&b=&b&d=x&&c=v

Mason %ARGS via libapreq2:
{
  'a' => [ '4', '1' ],
  'd&b' => 'x',
  'd&d&d' => '',
  '&&&a&b' => '',
  'b&d' => 'x',
  'b' => '',
  't' => '',
  '&c' => 'v'
};

Parsed via Apache2::RequestIO:
{
  'c' => 'v',
  'a' => [ undef, '4', '1' ],
  'b' => [ '', 'x', '', undef ],
  'd' => [ undef, undef, '', undef, 'x' ],
  't' => ''
};



Zbynek



Re: post body parsing

Posted by Torsten Förtsch <to...@gmx.net>.
On Wednesday, 20 July 2011 17:14:38 Zbynek Jun wrote:
> post body:
> a=&a&b=x&b=&b&a=x&c=x
> 
> ideal case:
> 'a' => [ '', '', 'x' ], 'b' => [ 'x', '', ''], 'c' => [ 'x']

I'd say the ideal case would be a list:

  'a', '', 'a', undef, 'b', 'x', 'b', undef, 'a', 'x', 'c', 'x'

Anything else drops information. "a=" is not necessarily the same as 
simply "a" and "a=1&b=2&a=3" is not necessarily the same as 
"a=1&a=3&b=2".

> from Apache2::Request:
> 'a' => '', 'b' => '', 'c' => 'x', 'a&b' => 'x', 'b&a' => 'x'
> 
>         Post body is properly encoded and posted with Content-Type 
> 'application/x-www-form-urlencoded; charset=UTF-8' via
> XMLHttpRequest.  Server is Apache/2.2.17 (FreeBSD), libapreq2-2.13.
> Some ideas ? Is it possible to get unparsed post body from
> Apache2::Request ?

You can read the request body via the Apache2::RequestRec object if 
Apache2::RequestIO is loaded.

  http://perl.apache.org/docs/2.0/api/Apache2/RequestIO.html#C_read_

Torsten Förtsch

-- 
Need professional modperl support? Hire me! (http://foertsch.name)

Like fantasy? http://kabatinte.net