You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Torsten Foertsch <to...@gmx.net> on 2005/05/27 15:34:36 UTC
[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
Re: [MP2]how to catch the response body of a subrequest?
Posted by Dorian Taylor <do...@foobarsystems.com>.
> 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
Re: [MP2]how to catch the response body of a subrequest?
Posted by Stas Bekman <st...@stason.org>.
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@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
Re: [MP2]how to catch the response body of a subrequest?
Posted by Dorian Taylor <do...@foobarsystems.com>.
> 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
Re: [MP2]how to catch the response body of a subrequest?
Posted by Stas Bekman <st...@stason.org>.
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@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
Re: [MP2]how to catch the response body of a subrequest?
Posted by Arne Skjaerholt <ar...@broadpark.no>.
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
Re: [ANNOUNCE] Apache2::TrapSubRequest 0.03
Posted by Joe Schaefer <jo...@sunstarsys.com>.
Tom Schindl <to...@gmx.at> writes:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> [...]
> Joe Schaefer schrieb:
>
> | my $content = "";
> | $subr->add_output_filter(bless sub : FilterRequestHandler {
> | my ($f, $bb) = @_;
> | while (my $e = $bb->first) {
> | $e->read(my $buf);
> | $content .= $buf;
> | $e->delete;
> | }
> | return Apache2::Const::OK;
> | });
> |
> | $subr->run; # reads entire subrequest into $content
>
> just for curiosity why do you bless the sub?
Cargo cult, I suppose; AFAICT it's not necessary.
Thanks for the spot.
--
Joe Schaefer
Re: [ANNOUNCE] Apache2::TrapSubRequest 0.03
Posted by Tom Schindl <to...@gmx.at>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
[...]
Joe Schaefer schrieb:
| my $content = "";
| $subr->add_output_filter(bless sub : FilterRequestHandler {
| my ($f, $bb) = @_;
| while (my $e = $bb->first) {
| $e->read(my $buf);
| $content .= $buf;
| $e->delete;
| }
| return Apache2::Const::OK;
| });
|
| $subr->run; # reads entire subrequest into $content
just for curiosity why do you bless the sub?
[...]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFCqUVXkVPeOFLgZFIRAoSFAJ47LkKdz0jjbumPJc2rKqJrekpKoACdGPEX
YWyNGh7JpP/Huu5iRQ88Ojk=
=QREe
-----END PGP SIGNATURE-----
Re: [ANNOUNCE] Apache2::TrapSubRequest 0.03
Posted by Dorian Taylor <do...@foobarsystems.com>.
> Hmm, have you considered removing the _filter sub and writing
> it as a closure instead? Here's some code that I've been using
> for that:
i suppose i could do that. today is clean-my-modules-and-get-them-on-cpan
day so perhaps later. ;)
.d
Re: [ANNOUNCE] Apache2::TrapSubRequest 0.03
Posted by Joe Schaefer <jo...@sunstarsys.com>.
Dorian Taylor <do...@foobarsystems.com> writes:
> http://search.cpan.org/~dorian/ - now with working tests.
>
> 0.03 should show up soon (forgot to remove the bit about
> ap_save_brigade in 0.02)
Hmm, have you considered removing the _filter sub and writing
it as a closure instead? Here's some code that I've been using
for that:
use base "Apache2::Filter";
...
my $content = "";
$subr->add_output_filter(bless sub : FilterRequestHandler {
my ($f, $bb) = @_;
while (my $e = $bb->first) {
$e->read(my $buf);
$content .= $buf;
$e->delete;
}
return Apache2::Const::OK;
});
$subr->run; # reads entire subrequest into $content
This way your subrequest buckets are all consumed by the filter,
and you don't need a pnote to store the captured subrequest
(I really don't know why you want to use ap_save_brigade). IMO
dynamically creating filters using closures is a really nifty
feature of mod_perl2; I use it to postprocess stuff stored
inside a mod_authz_svn-protected subversion repository. Just *try*
getting the authz info correct with a plain-old CGI script :-).
--
Joe Schaefer
[ANNOUNCE] Apache2::TrapSubRequest 0.03
Posted by Dorian Taylor <do...@foobarsystems.com>.
http://search.cpan.org/~dorian/ - now with working tests.
0.03 should show up soon (forgot to remove the bit about ap_save_brigade
in 0.02)