Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: ModPerl: ModPerl

[MP2]how to catch the response body of a subrequest?

 

 

ModPerl modperl RSS feed   Index | Next | Previous | View Threaded


torsten.foertsch at gmx

May 27, 2005, 6:34 AM

Post #1 of 8 (920 views)
Permalink
[MP2]how to catch the response body of a subrequest?

Hi,

is it possible to run a subrequest and send the output to a
PerlResponseHandler instead of the browser. I think it can be done with a
filter that gathers all output ...

Is there anything available like

$subr=$r->lookup_uri(...);
$response_body=$subr->run_with_output_to_me;
if( $subr->status==200 ) {
my $xyz=Storable::thaw( $response_body );
...
}

Torsten


arnsholt at broadpark

May 27, 2005, 9:33 AM

Post #2 of 8 (883 views)
Permalink
Re: [MP2]how to catch the response body of a subrequest? [In reply to]

According to the documentation for Apache (mp1 admittedly, but I don't
think this has changed in apache-2):
"Apache provides a sub-request mechanism to lookup a uri or filename,
performing all access checks, etc., without actually running the
response phase of the given request."
So that's probably not possible as the response is never generated.

Arne
:wq


stas at stason

May 27, 2005, 9:59 AM

Post #3 of 8 (883 views)
Permalink
Re: [MP2]how to catch the response body of a subrequest? [In reply to]

Torsten Foertsch wrote:
> Hi,
>
> is it possible to run a subrequest and send the output to a
> PerlResponseHandler instead of the browser. I think it can be done with a
> filter that gathers all output ...
>
> Is there anything available like
>
> $subr=$r->lookup_uri(...);
> $response_body=$subr->run_with_output_to_me;
> if( $subr->status==200 ) {
> my $xyz=Storable::thaw( $response_body );
> ...
> }

http://search.cpan.org/dist/Apache-TrapSubRequest/lib/Apache/TrapSubRequest.pm

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


stas at stason

May 27, 2005, 3:56 PM

Post #4 of 8 (884 views)
Permalink
Re: [MP2]how to catch the response body of a subrequest? [In reply to]

Dorian Taylor wrote:
>>http://search.cpan.org/dist/Apache-TrapSubRequest/lib/Apache/TrapSubRequest.pm
>
>
> this is actually broken. it needs the ap_save_brigade patch. i'm
> in a c mood so i think i'll hook up an xs version tonight. thanks
> for reminding me.

Or rewrite it to stash data from $bb->flatten, instead of stashing
brigades. In which case, no extra API is needed.


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


dorian at foobarsystems

May 27, 2005, 3:57 PM

Post #5 of 8 (882 views)
Permalink
Re: [MP2]how to catch the response body of a subrequest? [In reply to]

> http://search.cpan.org/dist/Apache-TrapSubRequest/lib/Apache/TrapSubRequest.pm

this is actually broken. it needs the ap_save_brigade patch. i'm
in a c mood so i think i'll hook up an xs version tonight. thanks
for reminding me.

.dorian


dorian at foobarsystems

May 27, 2005, 4:06 PM

Post #6 of 8 (883 views)
Permalink
Re: [MP2]how to catch the response body of a subrequest? [In reply to]

> Or rewrite it to stash data from $bb->flatten, instead of stashing
> brigades. In which case, no extra API is needed.

this is true. i'll put something up on cpan tonight.

.dorian


torsten.foertsch at gmx

Jul 1, 2008, 5:13 AM

Post #7 of 8 (784 views)
Permalink
Re: [MP2]how to catch the response body of a subrequest? [In reply to]

On Tue 01 Jul 2008, titetluc titetluc wrote:
> I am facing a problem: I would like to call sub-requests, but the content
> of these sub-requests should not 'pollute' the main request.

my $content='';
my $subr=$r->lookup_uri( $tmpl );
$subr->add_output_filter( sub {
my ($f, $bb) = @_;
while (my $e = $bb->first) {
$e->read(my $buf);
$content.=$buf;
$e->delete;
}
return Apache2::Const::OK;
} );
$subr->run;

Torsten

--
Need professional mod_perl support?
Just hire me: torsten.foertsch[at]gmx.net


titetluc at gmail

Jul 1, 2008, 6:00 AM

Post #8 of 8 (782 views)
Permalink
Re: [MP2]how to catch the response body of a subrequest? [In reply to]

Less than half an hour to have an answer !!!!
And the code is correctly running (my work now is to understand this cryptic
code ;-))

Thanks a lot


2008/7/1 Torsten Foertsch <torsten.foertsch[at]gmx.net>:

> On Tue 01 Jul 2008, titetluc titetluc wrote:
> > I am facing a problem: I would like to call sub-requests, but the content
> > of these sub-requests should not 'pollute' the main request.
>
> my $content='';
> my $subr=$r->lookup_uri( $tmpl );
> $subr->add_output_filter( sub {
> my ($f, $bb) = @_;
> while (my $e = $bb->first) {
> $e->read(my $buf);
> $content.=$buf;
> $e->delete;
> }
> return Apache2::Const::OK;
> } );
> $subr->run;
>
> Torsten
>
> --
> Need professional mod_perl support?
> Just hire me: torsten.foertsch[at]gmx.net
>

ModPerl modperl RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.