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 Dave Viner <da...@pobox.com> on 2007/01/30 21:36:21 UTC

APR::Request::Apache2 param() method

Hi,

I am having a strange problem with APR::Request::Apache2 and the param 
() method.  When I send a POST from Firefox, my code works  
perfectly.  When I send a POST from Safari or Windows/IE, my code fails.

Here is the HTML which displays the form to send:
         <form name="delete_alert" action="/mailing_list/remove"  
method="post" enctype="multipart/form-data">
         <input type="hidden" name="alerts_id" value="1234" />
         <input type="hidden" name="alerts_email"  
value="test@example.com">
         <input type="submit" name="submit" value="Remove">
         <input type="button" name="cancel" value="Cancel"  
onclick="document.location='/'; return false;">
         <br class="clearing">
         </form>

Here is the Perl code which handles this request:

     my $req = APR::Request::Apache2->handle($r);

     my($arg_status,$body_status) = $req->param_status();
     $r->log->debug("Parsing returned $arg_status, $body_status");

     if($r->method_number() == Apache2::Const::M_POST)
     {
         my $ps = $req->param();
         foreach my $k (keys(%$ps))
         {
             $r->log->warn("Got $k => " . $ps->{$k});
         }
         ## verify that we got an  alert id
         my $alert_id = $req->param('alerts_id');
         my $alert_email = $req->param('alerts_email');
         $r->log->debug("!!!!!!!!!!!! Checking params");
         if(!$alert_id)
         {
             $r->log->warn("no alert id given");
             return show_form($class, $r, $Site, $req, "Must pass a  
properly formatted alert id");
         }
         $r->log->debug("Have a good alert id");


Again, when Firefox sumbits this request, the code works perfectly...  
Here's a snippet from the error log showing the statements:

[Tue Jan 30 12:33:43 2007] [debug] /Users/dviner/Documents/amb/dev/ 
aboutmybaby/AMB/Handlers/MailingList/Remove.pm(17): [client  
127.0.0.1] using mod_perl handler for removing mailing list, referer:  
http://lalala.aboutmybaby.localhost/mailing_list/remove? 
alerts_email=bobo2@jones.com
Use of uninitialized value in concatenation (.) or string at /Users/ 
dviner/Documents/amb/dev/aboutmybaby/AMB/Handlers/MailingList/ 
Remove.pm line 43.
[Tue Jan 30 12:33:43 2007] [debug] /Users/dviner/Documents/amb/dev/ 
aboutmybaby/AMB/Handlers/MailingList/Remove.pm(43): [client  
127.0.0.1] Parsing returned Missing input data, , referer: http:// 
lalala.aboutmybaby.localhost/mailing_list/remove? 
alerts_email=bobo2@jones.com
[Tue Jan 30 12:33:43 2007] [debug] filter.c(269): [client 127.0.0.1]  
prefetching 65536 bytes, referer: http://lalala.aboutmybaby.localhost/ 
mailing_list/remove?alerts_email=bobo2@jones.com
[Tue Jan 30 12:33:43 2007] [warn] [client 127.0.0.1] Got alerts_id =>  
44505, referer: http://lalala.aboutmybaby.localhost/mailing_list/ 
remove?alerts_email=bobo2@jones.com
[Tue Jan 30 12:33:43 2007] [warn] [client 127.0.0.1] Got alerts_email  
=> bobo2@jones.com, referer: http://lalala.aboutmybaby.localhost/ 
mailing_list/remove?alerts_email=bobo2@jones.com
[Tue Jan 30 12:33:43 2007] [warn] [client 127.0.0.1] Got submit =>  
Remove, referer: http://lalala.aboutmybaby.localhost/mailing_list/ 
remove?alerts_email=bobo2@jones.com
[Tue Jan 30 12:33:43 2007] [debug] /Users/dviner/Documents/amb/dev/ 
aboutmybaby/AMB/Handlers/MailingList/Remove.pm(55): [client  
127.0.0.1] !!!!!!!!!!!! Checking params, referer: http:// 
lalala.aboutmybaby.localhost/mailing_list/remove? 
alerts_email=bobo2@jones.com
[Tue Jan 30 12:33:43 2007] [debug] /Users/dviner/Documents/amb/dev/ 
aboutmybaby/AMB/Handlers/MailingList/Remove.pm(61): [client  
127.0.0.1] Have a good alert id, referer: http:// 
lalala.aboutmybaby.localhost/mailing_list/remove? 
alerts_email=bobo2@jones.com


Here's the same request made from Mac/Safari or Win/IE
[Tue Jan 30 12:34:49 2007] [debug] /Users/dviner/Documents/amb/dev/ 
aboutmybaby/AMB/Handlers/MailingList/Remove.pm(17): [client  
127.0.0.1] using mod_perl handler for removing mailing list, referer:  
http://lalala.aboutmybaby.localhost/mailing_list/remove? 
alerts_email=bobo2@jones.com
Use of uninitialized value in concatenation (.) or string at /Users/ 
dviner/Documents/amb/dev/aboutmybaby/AMB/Handlers/MailingList/ 
Remove.pm line 43.
[Tue Jan 30 12:34:49 2007] [debug] /Users/dviner/Documents/amb/dev/ 
aboutmybaby/AMB/Handlers/MailingList/Remove.pm(43): [client  
127.0.0.1] Parsing returned Missing input data, , referer: http:// 
lalala.aboutmybaby.localhost/mailing_list/remove? 
alerts_email=bobo2@jones.com
[Tue Jan 30 12:34:49 2007] [debug] filter.c(269): [client 127.0.0.1]  
prefetching 65536 bytes, referer: http://lalala.aboutmybaby.localhost/ 
mailing_list/remove?alerts_email=bobo2@jones.com
[Tue Jan 30 12:34:49 2007] [debug] /Users/dviner/Documents/amb/dev/ 
aboutmybaby/AMB/Handlers/MailingList/Remove.pm(55): [client  
127.0.0.1] !!!!!!!!!!!! Checking params, referer: http:// 
lalala.aboutmybaby.localhost/mailing_list/remove? 
alerts_email=bobo2@jones.com
[Tue Jan 30 12:34:49 2007] [warn] [client 127.0.0.1] no alert id  
given, referer: http://lalala.aboutmybaby.localhost/mailing_list/ 
remove?alerts_email=bobo2@jones.com


Any suggestions on how to fix this?  My platform is:
[Tue Jan 30 12:33:01 2007] [notice] Apache/2.0.58 (Unix) PHP/5.1.4  
DAV/2 mod_apreq2-20051231/2.6.0 mod_perl/2.0.2 Perl/v5.8.8 configured  
-- resuming normal operations

thanks
dave



Re: APR::Request::Apache2 param() method

Posted by Joe Schaefer <jo...@sunstarsys.com>.
Dave Viner <da...@pobox.com> writes:

> removing the enctype makes no difference.  still encounter the same error.

OK, I think we're getting somewhere now.
Are you using code that calls CGI.pm from
a different handler (say in the auth phase)?

-- 
Joe Schaefer

Re: APR::Request::Apache2 param() method

Posted by Dave Viner <da...@pobox.com>.
removing the enctype makes no difference.  still encounter the same  
error.

i also added discard_request_body...  the code now reads:

     my $req = APR::Request::Apache2->handle($r);
     $r->discard_request_body;
     my($arg_status,$body_status) = $req->param_status();
     $r->log->debug("Parsing returned $arg_status, $body_status");  
#this is line 43

     if($r->method_number() == Apache2::Const::M_POST)
     {
         my $ps = $req->param();
         foreach my $k (keys(%$ps))
         {
             $r->log->warn("Got $k => " . $ps->{$k});
         }
         ## verify that we got an  alert id
         my $alert_id = $req->param('alerts_id');
         my $alert_email = $req->param('alerts_email');
         $r->log->debug("!!!!!!!!!!!! Checking params");
         if(!$alert_id)
         {
             $r->log->warn("no alert id given");



here's the output in the error log:

[Wed Jan 31 13:17:32 2007] [debug] /Users/dviner/Documents/amb/dev/ 
aboutmybaby/AMB/Handlers/MailingList/Remove.pm(17): [client  
127.0.0.1] using mod_perl handler for removing mailing list, referer:  
http://lalala.aboutmybaby.localhost/mailing_list/remove? 
alerts_email=bobo2@jones.com
Use of uninitialized value in concatenation (.) or string at /Users/ 
dviner/Documents/amb/dev/aboutmybaby/AMB/Handlers/MailingList/ 
Remove.pm line 43.
[Wed Jan 31 13:17:32 2007] [debug] /Users/dviner/Documents/amb/dev/ 
aboutmybaby/AMB/Handlers/MailingList/Remove.pm(43): [client  
127.0.0.1] Parsing returned Missing input data, , referer: http:// 
lalala.aboutmybaby.localhost/mailing_list/remove? 
alerts_email=bobo2@jones.com
[Wed Jan 31 13:17:32 2007] [debug] /Users/dviner/Documents/amb/dev/ 
aboutmybaby/AMB/Handlers/MailingList/Remove.pm(55): [client  
127.0.0.1] !!!!!!!!!!!! Checking params, referer: http:// 
lalala.aboutmybaby.localhost/mailing_list/remove? 
alerts_email=bobo2@jones.com
[Wed Jan 31 13:17:32 2007] [warn] [client 127.0.0.1] no alert id  
given, referer: http://lalala.aboutmybaby.localhost/mailing_list/ 
remove?alerts_email=bobo2@jones.com


I also tried to verify my sanity by using CGI.pm to print out what  
the parameters are that are received...
here's that output and code:

[Wed Jan 31 13:23:30 2007] [debug] /Users/dviner/Documents/amb/dev/ 
aboutmybaby/AMB/Handlers/MailingList/Remove.pm(18): [client  
127.0.0.1] using mod_perl handler for removing mailing list, referer:  
http://lalala.aboutmybaby.localhost/mailing_list/remove? 
alerts_email=bobo2@jones.com
Use of uninitialized value in concatenation (.) or string at /Users/ 
dviner/Documents/amb/dev/aboutmybaby/AMB/Handlers/MailingList/ 
Remove.pm line 44.
[Wed Jan 31 13:23:30 2007] [debug] /Users/dviner/Documents/amb/dev/ 
aboutmybaby/AMB/Handlers/MailingList/Remove.pm(44): [client  
127.0.0.1] Parsing returned Missing input data, , referer: http:// 
lalala.aboutmybaby.localhost/mailing_list/remove? 
alerts_email=bobo2@jones.com
[Wed Jan 31 13:23:30 2007] [warn] [client 127.0.0.1] Got [CGI]  
alerts_id => 44524, referer: http://lalala.aboutmybaby.localhost/ 
mailing_list/remove?alerts_email=bobo2@jones.com
[Wed Jan 31 13:23:30 2007] [warn] [client 127.0.0.1] Got [CGI]  
alerts_email => bobo2@jones.com, referer: http:// 
lalala.aboutmybaby.localhost/mailing_list/remove? 
alerts_email=bobo2@jones.com
[Wed Jan 31 13:23:30 2007] [warn] [client 127.0.0.1] Got [CGI] submit  
=> Remove, referer: http://lalala.aboutmybaby.localhost/mailing_list/ 
remove?alerts_email=bobo2@jones.com
[Wed Jan 31 13:23:30 2007] [debug] /Users/dviner/Documents/amb/dev/ 
aboutmybaby/AMB/Handlers/MailingList/Remove.pm(62): [client  
127.0.0.1] !!!!!!!!!!!! Checking params, referer: http:// 
lalala.aboutmybaby.localhost/mailing_list/remove? 
alerts_email=bobo2@jones.com
[Wed Jan 31 13:23:30 2007] [warn] [client 127.0.0.1] no alert id  
given, referer: http://lalala.aboutmybaby.localhost/mailing_list/ 
remove?alerts_email=bobo2@jones.com

CODE:

     my $req = APR::Request::Apache2->handle($r);
     $r->discard_request_body;
     my($arg_status,$body_status) = $req->param_status();
     $r->log->debug("Parsing returned $arg_status, $body_status");

     if($r->method_number() == Apache2::Const::M_POST)
     {
         my $ps = $req->param();
         foreach my $k (keys(%$ps))
         {
             $r->log->warn("Got [APR::Request::Apache2] $k => " . $ps- 
 >{$k});
         }
         my $cgi = CGI->new($r);
         my $pscgi = $cgi->Vars();
         foreach my $k (keys(%$pscgi))
         {
             $r->log->warn("Got [CGI] $k => " . $pscgi->{$k});
         }
         ## verify that we got an  alert id
         my $alert_id = $req->param('alerts_id');
         my $alert_email = $req->param('alerts_email');
         $r->log->debug("!!!!!!!!!!!! Checking params");
         if(!$alert_id)
         {
             $r->log->warn("no alert id given");


How is it that CGI.pm finds the parameter and APR::Request::Apache2  
does not??

thanks
dave




On Jan 30, 2007, at 12:49 PM, Joe Schaefer wrote:

> Dave Viner <da...@pobox.com> writes:
>
>> Hi,
>>
>> I am having a strange problem with APR::Request::Apache2 and the  
>> param
>> () method.  When I send a POST from Firefox, my code works  
>> perfectly.  When I
>> send a POST from Safari or Windows/IE, my code fails.
>>
>> Here is the HTML which displays the form to send:
>>         <form name="delete_alert" action="/mailing_list/remove"  
>> method="post"
>> enctype="multipart/form-data">
>   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
> Have you tried it with the default enctype?
>
>>         <input type="hidden" name="alerts_id" value="1234" />
>>         <input type="hidden" name="alerts_email"  
>> value="test@example.com">
>>         <input type="submit" name="submit" value="Remove">
>>         <input type="button" name="cancel" value="Cancel"
>> onclick="document.location='/'; return false;">
>>         <br class="clearing">
>>         </form>
>>
>> Here is the Perl code which handles this request:
>>
>>     my $req = APR::Request::Apache2->handle($r);
>
> Try adding
>
>       $r->discard_request_body;
>
> here, and then see what the body_status is.
> (The code didn't croak, so I don't think you're getting
> an error, but let's see anyhow).
>
> -- 
> Joe Schaefer


Re: APR::Request::Apache2 param() method

Posted by Joe Schaefer <jo...@sunstarsys.com>.
Dave Viner <da...@pobox.com> writes:

> Hi,
>
> I am having a strange problem with APR::Request::Apache2 and the param
> () method.  When I send a POST from Firefox, my code works perfectly.  When I
> send a POST from Safari or Windows/IE, my code fails.
>
> Here is the HTML which displays the form to send:
>         <form name="delete_alert" action="/mailing_list/remove" method="post"
> enctype="multipart/form-data">
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Have you tried it with the default enctype?

>         <input type="hidden" name="alerts_id" value="1234" />
>         <input type="hidden" name="alerts_email" value="test@example.com">
>         <input type="submit" name="submit" value="Remove">
>         <input type="button" name="cancel" value="Cancel"
> onclick="document.location='/'; return false;">
>         <br class="clearing">
>         </form>
>
> Here is the Perl code which handles this request:
>
>     my $req = APR::Request::Apache2->handle($r);

Try adding

      $r->discard_request_body;

here, and then see what the body_status is.
(The code didn't croak, so I don't think you're getting
an error, but let's see anyhow).

-- 
Joe Schaefer