Mailing List Archive

How to read request content without eating it ?
Hello,

I need to implement an access control handler based on request content.

So here is my (very simplified) PerlAccessHandler code :
sub handler {
$r = shift;
$r->read($content,$r->headers_in->{'Content-length'});
if($content =~ /signature=expected_signature/)
{
return Apache2::Const::OK;
}
return Apache2::Const::AUTH_REQUIRED;
}

It works.
My problem is further, when handler returns OK and Apache runs the user requested CGI script.
The request content provides some additional parameters the target CGI script needs.
However, as soon as $r->read is used, request content is no more available to the CGI script.

So my question is, how to read request content without making it unavailable to the final requested CGI ?

Thank you very much,

Best regards,

Ben
Re: How to read request content without eating it ? [ In reply to ]
Use apreq.

Sent from my iPhone

> On Feb 28, 2016, at 1:04 PM, Ben RUBSON <ben.rubson@gmail.com> wrote:
>
> Hello,
>
> I need to implement an access control handler based on request content.
>
> So here is my (very simplified) PerlAccessHandler code :
> sub handler {
> $r = shift;
> $r->read($content,$r->headers_in->{'Content-length'});
> if($content =~ /signature=expected_signature/)
> {
> return Apache2::Const::OK;
> }
> return Apache2::Const::AUTH_REQUIRED;
> }
>
> It works.
> My problem is further, when handler returns OK and Apache runs the user requested CGI script.
> The request content provides some additional parameters the target CGI script needs.
> However, as soon as $r->read is used, request content is no more available to the CGI script.
>
> So my question is, how to read request content without making it unavailable to the final requested CGI ?
>
> Thank you very much,
>
> Best regards,
>
> Ben
>
Re: How to read request content without eating it ? [ In reply to ]
Joseph,

Thank you very much, now it works as expected :

sub handler {
$r = shift;
my $q = Apache2::Request->new($r);
if($q->param('signature') eq "expected_signature")
{
return Apache2::Const::OK;
}
return Apache2::Const::AUTH_REQUIRED;
}

Thank you again,

Ben



> Le 28 févr. 2016 à 20:13, Joseph Schaefer <joe_schaefer@yahoo.com> a écrit :
>
> Use apreq.
>
> Sent from my iPhone
>
>> On Feb 28, 2016, at 1:04 PM, Ben RUBSON <ben.rubson@gmail.com> wrote:
>>
>> Hello,
>>
>> I need to implement an access control handler based on request content.
>>
>> So here is my (very simplified) PerlAccessHandler code :
>> sub handler {
>> $r = shift;
>> $r->read($content,$r->headers_in->{'Content-length'});
>> if($content =~ /signature=expected_signature/)
>> {
>> return Apache2::Const::OK;
>> }
>> return Apache2::Const::AUTH_REQUIRED;
>> }
>>
>> It works.
>> My problem is further, when handler returns OK and Apache runs the user requested CGI script.
>> The request content provides some additional parameters the target CGI script needs.
>> However, as soon as $r->read is used, request content is no more available to the CGI script.
>>
>> So my question is, how to read request content without making it unavailable to the final requested CGI ?
>>
>> Thank you very much,
>>
>> Best regards,
>>
>> Ben
>>