You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Anthony Gardner <cy...@yahoo.co.uk> on 2007/03/29 16:27:26 UTC

Sub Requests

All, I've now had a chance to look at implementing sub requests and it seems to be the thing I need but .............

I need some more info that I've been unable to get from the book or the web.

To begin with, the environment passed to the sub request has to be managed and I've half succeeded but have questions.

I can use PassEnv and PerlPassEnv, set them in the calling script and then retrieve the values in the called script (sub request) ........ cool!!

But, I do loose my QUERY_STRING and infact, I'd like to change the QUERY_STRING for the called sub request.

I've tried subprocess_env but from what I can see, that's only good to pass stuff along the chain of commands in the same request. Although this is a sub request, I'm assunming it's not 'the same' request as the caled script.

So, how do I do that.

Other points of interest are ............

SERVER_PROTOCOL changes from HTTP/1.1 to INCLUDED
SERVER_PORT changes from 8881 to 80
SCRIPT_URI is the same in the sub request as the called script except that the port is missing (it's now 80)
SCRIPT_NAME and SCRIPT_FILENAME have changed as expected.

Again, thanks for all your help in this so far but unless I'm looking in the wrong place, I've found the docs terse and thin on the ground.

CIA

-Ants



 		
---------------------------------
 What kind of emailer are you? Find out today - get a free analysis of your email personality. Take the quiz at the Yahoo! Mail Championship.

Re: Sub Requests

Posted by Joe Schaefer <jo...@sunstarsys.com>.
Anthony Gardner <cy...@yahoo.co.uk> writes:

> Okay, including the new query string in the lookup_uri now correctly
> populates the QUERY_STRING in the sub request but 
> that isn;t the answer to my problems.
>
> Within the called script, we make a call to $cgi->Vars but this is
> returning the query string from the initial request.  Is it taking
> that from the REQUEST_URI? I thought it would take it from the
> QUERY_STRING ......... hence me concentrating 
> on that area.

Make sure your calls to CGI all pass the optional $r argument.
Otherwise use APR::Request, which handles subrequests correctly.

Btw, capturing the output of a subrequest can be done with a closure.
I'm sure I posted some code to do that here at one time or another.


-- 
Joe Schaefer


Re: Sub Requests

Posted by Anthony Gardner <cy...@yahoo.co.uk>.
Cool. you're a diamond.

stay tuned for the next problem!!

Perrin Harkins <ph...@gmail.com> wrote: On 3/30/07, Anthony Gardner  wrote:
> One more question, I had to put the data in notes so that it was available
> in the inital script. Is that the right way to do it?

That's a good way to do it.  I think the alternative is to rig some
kind of filter to capture the output of the request, which is probably
a lot more work.

> Perrin, thanks for all your help on this.

No sweat.  Glad to hear it's working for you now.

- Perrin


 		
---------------------------------
 New Yahoo! Mail is the ultimate force in competitive emailing. Find out more at the Yahoo! Mail Championships. Plus: play games and win prizes.

Re: Sub Requests

Posted by Perrin Harkins <ph...@gmail.com>.
On 3/30/07, Anthony Gardner <cy...@yahoo.co.uk> wrote:
> One more question, I had to put the data in notes so that it was available
> in the inital script. Is that the right way to do it?

That's a good way to do it.  I think the alternative is to rig some
kind of filter to capture the output of the request, which is probably
a lot more work.

> Perrin, thanks for all your help on this.

No sweat.  Glad to hear it's working for you now.

- Perrin

Re: Sub Requests

Posted by Anthony Gardner <cy...@yahoo.co.uk>.
Ooooooooookay. Had a play with initalising the globals and got the thing working. 

One more question, I had to put the data in notes so that it was available in the inital script. Is that the right way to do it?

Perrin, thanks for all your help on this. I've learnt a lot more, too which is also good.

-Ants

Perrin Harkins <ph...@gmail.com> wrote: On 3/30/07, Anthony Gardner  wrote:
> Within the called script, we make a call to $cgi->Vars but this is returning
> the query string from the initial request.

That's just a problem with the way CGI.pm is coded.  It essentially
doesn't work for subrequests or internal redirects because of the
massive use of global variables.  A call to CGI::_reset_globals should
fix it.

- Perrin


 		
---------------------------------
 Now you can have your favourite RSS headlines come to you with the all new Yahoo! Mail.

Re: Sub Requests

Posted by Perrin Harkins <ph...@gmail.com>.
On 3/30/07, Anthony Gardner <cy...@yahoo.co.uk> wrote:
> Within the called script, we make a call to $cgi->Vars but this is returning
> the query string from the initial request.

That's just a problem with the way CGI.pm is coded.  It essentially
doesn't work for subrequests or internal redirects because of the
massive use of global variables.  A call to CGI::_reset_globals should
fix it.

- Perrin

Re: Sub Requests

Posted by Anthony Gardner <cy...@yahoo.co.uk>.
Yeah, you know what, I was mistakingly using lookup_file for ages and then changed to lookup_uri but then overlooked the possibilty of adding on the qsuery string.

Ho hum, will try tomorrow. Am getting there slowly.

Perrin Harkins <ph...@gmail.com> wrote: On 3/29/07, Anthony Gardner  wrote:
> I can use PassEnv and PerlPassEnv, set them in the calling script and then
> retrieve the values in the called script (sub request) ........ cool!!

You could also put things in $r->pnotes().  The parent request object
is available from within the subrequest.

> But, I do loose my QUERY_STRING and infact, I'd like to change the
> QUERY_STRING for the called sub request.

I think you just need to construct a URL with the query string you
want and use it as your subrequest URL.

- Perrin


 		
---------------------------------
 What kind of emailer are you? Find out today - get a free analysis of your email personality. Take the quiz at the Yahoo! Mail Championship.

Re: Sub Requests

Posted by Anthony Gardner <cy...@yahoo.co.uk>.
Okay, including the new query string in the lookup_uri now correctly populates the QUERY_STRING in the sub request but that isn;t the answer to my problems.

Within the called script, we make a call to $cgi->Vars but this is returning the query string from the initial request. Is it taking that from the REQUEST_URI? I thought it would take it from the QUERY_STRING ......... hence me concentrating on that area.

The REQUEST_URI in the called script remains the same as the intitial request.

I could code around all of these problems but that's amaturish and I'd rather spend a bit of time getting ti the core of this.

Any further help would be great, thanks

CIA

-Ants

Perrin Harkins <ph...@gmail.com> wrote: On 3/29/07, Anthony Gardner  wrote:
> I can use PassEnv and PerlPassEnv, set them in the calling script and then
> retrieve the values in the called script (sub request) ........ cool!!

You could also put things in $r->pnotes().  The parent request object
is available from within the subrequest.

> But, I do loose my QUERY_STRING and infact, I'd like to change the
> QUERY_STRING for the called sub request.

I think you just need to construct a URL with the query string you
want and use it as your subrequest URL.

- Perrin


 		
---------------------------------
 New Yahoo! Mail is the ultimate force in competitive emailing. Find out more at the Yahoo! Mail Championships. Plus: play games and win prizes.

Re: Sub Requests

Posted by Perrin Harkins <ph...@gmail.com>.
On 3/29/07, Anthony Gardner <cy...@yahoo.co.uk> wrote:
> I can use PassEnv and PerlPassEnv, set them in the calling script and then
> retrieve the values in the called script (sub request) ........ cool!!

You could also put things in $r->pnotes().  The parent request object
is available from within the subrequest.

> But, I do loose my QUERY_STRING and infact, I'd like to change the
> QUERY_STRING for the called sub request.

I think you just need to construct a URL with the query string you
want and use it as your subrequest URL.

- Perrin