You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Jan Algermissen <ja...@topicmapping.com> on 2004/01/02 20:11:18 UTC

poking into request content?

Hi,

I want to write a Perl handler that pokes into the content
of a request in order to see if a certain parameter is present and
if so to change the request method.

Ok, I am finally aware that content() may onle be called once on
a request object so any further handlers won't be able to see the
original content.

Is there a way to restore that data after calling content() or read()?

(I had the idea that calling read might silently make the data available
via content() too, but unfortunately this is not true.

The practical reason for my question can be found here:

http://search.cpan.org/~alger/Apache-MagicPOST/

Thanks for any help or ideas.


Jan


-- 
Jan Algermissen                           http://www.topicmapping.com
Consultant & Programmer	                  http://www.gooseworks.org

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


Re: poking into request content?

Posted by Stas Bekman <st...@stason.org>.
Jan Algermissen wrote:
> Geoffrey Young wrote:
> 
>>Jan Algermissen wrote:
>>
>>>Hi,
>>>
>>>I want to write a Perl handler that pokes into the content
>>>of a request in order to see if a certain parameter is present and
>>>if so to change the request method.
>>>
>>>Ok, I am finally aware that content() may onle be called once on
>>>a request object so any further handlers won't be able to see the
>>>original content.
>>>
>>>Is there a way to restore that data after calling content() or read()?
>>
>>see Apache::Request->instance()
> 
> 
> Geoffrey--
> 
> thanks. I tried that but am I right in suspecting that subsequent handlers
> also need to work with Apache::Request? IOW: is there a way to use Apache::Request
> and later use the notrmal $r->content() call?

Not really. You could subclass $r, but your other handlers need to be aware of 
this. So it's not transparent.

> I want to impose abslolutely no constraint on subsequent handlers (as they
> might not even be related to my application).

In which case you probably need to look at input filters available only with 
mod_perl 2. Though remember that the body filter will be invoked only if some 
handler is trying to consume the body.

In fact Apache::Request 2, does exactly that - it injects itself as a filter, 
making the POSTed body available to any consumer that calls into libapreq's 
instance method (perl, c, php, whatever)

__________________________________________________________________
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: poking into request content?

Posted by Jan Algermissen <ja...@topicmapping.com>.
Geoffrey Young wrote:
> 
> Jan Algermissen wrote:
> > Hi,
> >
> > I want to write a Perl handler that pokes into the content
> > of a request in order to see if a certain parameter is present and
> > if so to change the request method.
> >
> > Ok, I am finally aware that content() may onle be called once on
> > a request object so any further handlers won't be able to see the
> > original content.
> >
> > Is there a way to restore that data after calling content() or read()?
> 
> see Apache::Request->instance()

Geoffrey--

thanks. I tried that but am I right in suspecting that subsequent handlers
also need to work with Apache::Request? IOW: is there a way to use Apache::Request
and later use the notrmal $r->content() call?

I want to impose abslolutely no constraint on subsequent handlers (as they
might not even be related to my application).

Jan


> 
> HTH
> 
> --Geoff

-- 
Jan Algermissen                           http://www.topicmapping.com
Consultant & Programmer	                  http://www.gooseworks.org

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


Re: poking into request content?

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

Jan Algermissen wrote:
> Hi,
> 
> I want to write a Perl handler that pokes into the content
> of a request in order to see if a certain parameter is present and
> if so to change the request method.
> 
> Ok, I am finally aware that content() may onle be called once on
> a request object so any further handlers won't be able to see the
> original content.
> 
> Is there a way to restore that data after calling content() or read()?

see Apache::Request->instance()

HTH

--Geoff


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