You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Andrew Maltsev <am...@xao.com> on 2003/12/08 20:05:24 UTC

mod_perl 1.x, getting POST'ed content

Here is the situation. There is sort of web service (Ariba buyer for
those who cares) that posts plain unencoded XML using POST method to a
mod_perl 1.x application.

Somewhere at the very top the application does

use CGI;
my $cgi=CGI->new();

and then passes this $cgi reference around. Assuming that this CANNOT BE
CHANGED, i.e. we get called sometime in the middle and have no control
over what's above us, is there a way to get the XML message posted to us?

$r->content returns '' as it was already called once by CGI. CGI does
not save the content anywhere -- it parses it instead. And while
parsing, it assumes that arguments can be separated by both ';' and '&'.
So that if we join arguments back we either convert all ';'s into '&'s
or vice versa.

Any ideas?

So far I can only see customizing CGI.pm to make it save original
POST'ed content.


Andrew.

-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html


Re: mod_perl 1.x, getting POST'ed content

Posted by Geoffrey Young <ge...@modperlcookbook.org>.

Andrew Maltsev wrote:
> Here is the situation. There is sort of web service (Ariba buyer for
> those who cares) that posts plain unencoded XML using POST method to a
> mod_perl 1.x application.
> 
> Somewhere at the very top the application does
> 
> use CGI;
> my $cgi=CGI->new();
> 
> and then passes this $cgi reference around. Assuming that this CANNOT BE
> CHANGED, i.e. we get called sometime in the middle and have no control
> over what's above us, is there a way to get the XML message posted to us?
> 
> $r->content returns '' as it was already called once by CGI. CGI does
> not save the content anywhere -- it parses it instead. And while
> parsing, it assumes that arguments can be separated by both ';' and '&'.
> So that if we join arguments back we either convert all ';'s into '&'s
> or vice versa.
> 
> Any ideas?
> 
> So far I can only see customizing CGI.pm to make it save original
> POST'ed content.

if you're using Apache::Registry for your cgi script then you can try
something like this:

http://www.modperlcookbook.org/~geoff/modules/experimental/Apache-CachePOSTRegistry-0.01.tar.gz

sorry there are not docs at the moment, but basically all you do is change

 PerlHandler Apache::Registry

to

 PerlHandler Apache::CachePOSTRegistry

please note that the module is experimental - I hacked it together and made
sure it worked, but that's about all :)

good luck

--Geoff


-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html


Re: mod_perl 1.x, getting POST'ed content

Posted by Stas Bekman <st...@stason.org>.
Andrew Maltsev wrote:
> On Mon, Dec 08, 2003 at 12:31:59PM -0800, Stas Bekman wrote:
> 
>>Andrew Maltsev wrote:
>>[...]
>>
>>>>Slurp STDIN before you call CGI->new() into an IO::String object,
>>>
>>>
>>>Can't. I get references to $cgi and $r, that's given. I tried getting
>>>filehandle ($r->connection->fileno(0)), rewinding it and reading again
>>>-- that works in http, but does not in https requests.
>>
>>Can't do what? Slurp the data?
>>
>>  $r->read(my $data, $r->headers_in{'Content-Length'});
> 
> 
> It's a complicated multi-thousands lines application (an application
> server rather) I have no control over at this point. My module gets
> executed in the middle, where I get $r and $cgi. I can't (well not
> easily anyway) modify the part around creating that $cgi reference.
> 
> I was just making sure there are no other easier options. Like the
> content being already stored somewhere in the apache core where I can
> still retrieve it from.

Yes, you can.

Use an earlier phase to slurp the file in. e.g. if you run your code only in 
PerlHandler phase, you could use PerlFixupHandler on an earlier phase to slurp 
STDIN, then reopen it to a different filehandle which CGI will use without 
being aware that it's not the original STDIN.

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html


Re: mod_perl 1.x, getting POST'ed content

Posted by Andrew Maltsev <am...@xao.com>.
On Mon, Dec 08, 2003 at 12:31:59PM -0800, Stas Bekman wrote:
> Andrew Maltsev wrote:
> [...]
> >>Slurp STDIN before you call CGI->new() into an IO::String object,
> > 
> > 
> > Can't. I get references to $cgi and $r, that's given. I tried getting
> > filehandle ($r->connection->fileno(0)), rewinding it and reading again
> > -- that works in http, but does not in https requests.
> 
> Can't do what? Slurp the data?
> 
>   $r->read(my $data, $r->headers_in{'Content-Length'});

It's a complicated multi-thousands lines application (an application
server rather) I have no control over at this point. My module gets
executed in the middle, where I get $r and $cgi. I can't (well not
easily anyway) modify the part around creating that $cgi reference.

I was just making sure there are no other easier options. Like the
content being already stored somewhere in the apache core where I can
still retrieve it from.


Andrew.

> 
> __________________________________________________________________
> Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
> http://stason.org/     mod_perl Guide ---> http://perl.apache.org
> mailto:stas@stason.org http://use.perl.org http://apacheweek.com
> http://modperlbook.org http://apache.org   http://ticketmaster.com
> 

-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html


Re: mod_perl 1.x, getting POST'ed content

Posted by Stas Bekman <st...@stason.org>.
Andrew Maltsev wrote:
[...]
>>Slurp STDIN before you call CGI->new() into an IO::String object,
> 
> 
> Can't. I get references to $cgi and $r, that's given. I tried getting
> filehandle ($r->connection->fileno(0)), rewinding it and reading again
> -- that works in http, but does not in https requests.

Can't do what? Slurp the data?

  $r->read(my $data, $r->headers_in{'Content-Length'});

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html


Re: mod_perl 1.x, getting POST'ed content

Posted by Andrew Maltsev <am...@xao.com>.
On Mon, Dec 08, 2003 at 11:42:43AM -0800, Stas Bekman wrote:
> Andrew Maltsev wrote:
> > So far I can only see customizing CGI.pm to make it save original
> > POST'ed content.
> 
> If Geoff's module doesn't work for you, you could do the following:

The application does not use Apache::Registry, it has its own
handler. But it gave me an idea, may be I can subclass $r in my own
handler before passing it along -- something like that, I'm going to try
it..

> Slurp STDIN before you call CGI->new() into an IO::String object,

Can't. I get references to $cgi and $r, that's given. I tried getting
filehandle ($r->connection->fileno(0)), rewinding it and reading again
-- that works in http, but does not in https requests.



Andrew.

-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html


Re: mod_perl 1.x, getting POST'ed content

Posted by Stas Bekman <st...@stason.org>.
Andrew Maltsev wrote:
> Here is the situation. There is sort of web service (Ariba buyer for
> those who cares) that posts plain unencoded XML using POST method to a
> mod_perl 1.x application.
> 
> Somewhere at the very top the application does
> 
> use CGI;
> my $cgi=CGI->new();
> 
> and then passes this $cgi reference around. Assuming that this CANNOT BE
> CHANGED, i.e. we get called sometime in the middle and have no control
> over what's above us, is there a way to get the XML message posted to us?
> 
> $r->content returns '' as it was already called once by CGI. CGI does
> not save the content anywhere -- it parses it instead. And while
> parsing, it assumes that arguments can be separated by both ';' and '&'.
> So that if we join arguments back we either convert all ';'s into '&'s
> or vice versa.
> 
> Any ideas?
> 
> So far I can only see customizing CGI.pm to make it save original
> POST'ed content.

If Geoff's module doesn't work for you, you could do the following:

Slurp STDIN before you call CGI->new() into an IO::String object, and then 
either re-open STDIN as that IO::String object or try to tell CGI::new to use 
that IO instead of STDIN (you can even pass the slurped data as a string, 
though it's probably not the most efficient way). Starting from perl 5.8 you 
can also use in-memory filehandles which act similarly. See perldoc -f open 
for more info on that cool new feature.

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html