You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Perrin Harkins <ph...@gmail.com> on 2007/03/26 16:57:52 UTC

Re: internal_redirect & ModPerlRegistr

On 3/26/07, Anthony Gardner <cy...@yahoo.co.uk> wrote:
> Can I only use internal_redirect in handlers or is it possible to use it
> within a cgi script calling another cgi script?

If by "CGI script" you mean something running ModPerl::Registry, then
yes, it works fine.  If you mean a perl program called through mod_cgi
and not mod_perl, then no.  You would have to fake that with LWP or
similar.

> my $r = $self->_request_rec();

That looks pretty scary.  Where is the value of $self->_request_rec()
coming from?  If you keep a RequestRec object around and try to use it
in a later request, bad things will happen (segfaults).

- Perrin

Re: internal_redirect & ModPerlRegist

Posted by Anthony Gardner <cy...@yahoo.co.uk>.
Nothing means .......... not working. It's not entering the called script.

As for $r, the $self is actually a WWW::Utils package and some of the routines within that package call on Apache->request when running under MP. Nothing gets stored.

I know the called CGI script is passed $r but I thought it was better/cleaner to call it as I have.

I'm not at work now so will have to look at this further tomorrow. As long as I know I should be able to do it, then I have a goal.

I tried sub requests ......... from memory, sth like

$sub_rec = $r->lookup_file( '/path/to/script');
$rc = $sub_rec->run()

and although that entered the script, I didn;t get 200 returned. Plus, where would the content be? Stored in the $sub_rec?

Will look into this further tomorrow.

Thanks very, very much for all your help thus far .......... will get back to you ;)

-Ants

Perrin Harkins <ph...@gmail.com> wrote: On 3/26/07, Anthony Gardner  wrote:
> The script is running under ModPerlRegistry but nothing is happening.

What's your definition of "nothing" in this case?

>  So, am I right in now thinking, because my cgi script gets wrapped by a
> handler, it's considered a content handler?

Yes.  But see my other response -- you probably don't want
internal_redirect if you're trying to gather up the output.

>  As for the $r, it's coming from Apache->request() ............ but we are
> experiencing segfaults

Are you using mod_perl 2?  If so, you should be calling it like this:
$r = Apache2::RequestUtil->request;

The code you showed looked like it was trying to cache $r in some
other object, which you have to be really careful about.  You're
likely to accidentally keep one around and try to use the $r from a
previous request, especially if you get into subrequests and
internal_redirects.

- Perrin


 		
---------------------------------
 Now you can scan emails quickly with a reading pane. Get the new Yahoo! Mail.

Re: internal_redirect & ModPerlRegist

Posted by Perrin Harkins <ph...@gmail.com>.
On 3/26/07, Anthony Gardner <cy...@yahoo.co.uk> wrote:
> The script is running under ModPerlRegistry but nothing is happening.

What's your definition of "nothing" in this case?

>  So, am I right in now thinking, because my cgi script gets wrapped by a
> handler, it's considered a content handler?

Yes.  But see my other response -- you probably don't want
internal_redirect if you're trying to gather up the output.

>  As for the $r, it's coming from Apache->request() ............ but we are
> experiencing segfaults

Are you using mod_perl 2?  If so, you should be calling it like this:
$r = Apache2::RequestUtil->request;

The code you showed looked like it was trying to cache $r in some
other object, which you have to be really careful about.  You're
likely to accidentally keep one around and try to use the $r from a
previous request, especially if you get into subrequests and
internal_redirects.

- Perrin

Re: internal_redirect & ModPerlRegistr

Posted by Perrin Harkins <ph...@gmail.com>.
On 3/26/07, Torsten Foertsch <to...@gmx.net> wrote:
> Not entirely true, a CGI script (mod_cgid?) can generate an internal redirect
> saying
>
> Status: 200
> Location: /path/to/other.html
>
> Both mod_cgi and mod_cgid contain this code:
>
>         if (location && location[0] == '/' && r->status == 200) {
>             /* This redirect needs to be a GET no matter what the original
>              * method was.
>              */
>             r->method = apr_pstrdup(r->pool, "GET");
>             r->method_number = M_GET;
>
>             /* We already read the message body (if any), so don't allow
>              * the redirected request to think it has one.  We can ignore
>              * Transfer-Encoding, since we used REQUEST_CHUNKED_ERROR.
>              */
>             apr_table_unset(r->headers_in, "Content-Length");
>
>             ap_internal_redirect_handler(location, r);
>             return OK;
>         }

Interesting.  Now that I look at what Anthony wanted to do though, it
doesn't seem very useful for his case, since he wants to collect the
output.  In fact, an internal_redirect in general is not right for
that.  You need a subrequest instead.

> As for Modperl::Registry, you need to use the perl-script handler and enable
> PerlOptions +ParseHeaders. Then the same approach works also for Registry
> scripts, see modperl_cgi.c:modperl_cgi_header_parse().

In ModPerl::Registry, you don't need to resort to tricks like that.
You get passed an Apache2::RequestRec object to do whatever you like
with.

- Perrin

Re: internal_redirect & ModPerlRegistr

Posted by Torsten Foertsch <to...@gmx.net>.
On Monday 26 March 2007 16:57, Perrin Harkins wrote:
> On 3/26/07, Anthony Gardner <cy...@yahoo.co.uk> wrote:
> > Can I only use internal_redirect in handlers or is it possible to use it
> > within a cgi script calling another cgi script?
>
> If by "CGI script" you mean something running ModPerl::Registry, then
> yes, it works fine.  If you mean a perl program called through mod_cgi
> and not mod_perl, then no.  You would have to fake that with LWP or
> similar.

Not entirely true, a CGI script (mod_cgid?) can generate an internal redirect 
saying

Status: 200
Location: /path/to/other.html

Both mod_cgi and mod_cgid contain this code:

        if (location && location[0] == '/' && r->status == 200) {
            /* This redirect needs to be a GET no matter what the original
             * method was.
             */
            r->method = apr_pstrdup(r->pool, "GET");
            r->method_number = M_GET;

            /* We already read the message body (if any), so don't allow
             * the redirected request to think it has one.  We can ignore
             * Transfer-Encoding, since we used REQUEST_CHUNKED_ERROR.
             */
            apr_table_unset(r->headers_in, "Content-Length");

            ap_internal_redirect_handler(location, r);
            return OK;
        }

As for Modperl::Registry, you need to use the perl-script handler and enable 
PerlOptions +ParseHeaders. Then the same approach works also for Registry 
scripts, see modperl_cgi.c:modperl_cgi_header_parse().

Torsten



Re: internal_redirect & ModPerlRegistr

Posted by Fred Moyer <fr...@redhotpenguin.com>.
Perrin Harkins wrote:
> On 3/26/07, Torsten Foertsch <to...@gmx.net> wrote:
>> switch to mp2. It's much more stable.
> 
> I'm not aware of any stability issues in mp1.  Switch to mp2 if you
> want the new features.  You don't need to switch for stability.

In addition to new features, there is a speed advantage.  I just spent a 
good deal of time benchmarking mp1 vs mp2 on a project.  Mp2 was faster 
in terms of elapsed request time taken, in the double digits percentage 
wise vs mp1 for the exact same configuration for small amounts of data 
being returned by the response phase.  I can't post the exact details 
due to an nda, but I can say with confidence that "it's definitely 
faster" :)

Re: internal_redirect & ModPerlRegistr

Posted by Perrin Harkins <ph...@gmail.com>.
On 3/26/07, Torsten Foertsch <to...@gmx.net> wrote:
> switch to mp2. It's much more stable.

I'm not aware of any stability issues in mp1.  Switch to mp2 if you
want the new features.  You don't need to switch for stability.

- Perrin

Re: internal_redirect & ModPerlRegistr

Posted by Malcolm J Harwood <mj...@liminalflux.net>.
On Monday 26 March 2007, Anthony Gardner wrote:
> This is MP2 ........... actually RHE 1.99. We have compiled a test MP2 but
> still get seg faults.

Ah, that's possibly not actually MP2. RH shipped a pre-release version of MP, 
and there were a lot of changes and bug fixes after that point (including a 
namespace change for a lot of the modules).

If you're using anything tagged 1.99x, it's an unsupported version and you 
really need to upgrade to a stable release of MP2.

Re: internal_redirect & ModPerlRegistr

Posted by Anthony Gardner <cy...@yahoo.co.uk>.
This is MP2 ........... actually RHE 1.99. We have compiled a test MP2 but still get seg faults.

Am not at work now but will look at this further tomorrow.



Torsten Foertsch <to...@gmx.net> wrote: On Monday 26 March 2007 17:51, Anthony Gardner wrote:
>  As for the $r, it's coming from Apache->request()

So, it's mp1 then. Set PerlSendHeader to On then try the approach given in my 
previous mail. I don't know for sure because I have switched to mp2 several 
years ago.

>  but we are 
> experiencing segfaults

switch to mp2. It's much more stable.

Torsten


 		
---------------------------------
 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: internal_redirect & ModPerlRegistr

Posted by Torsten Foertsch <to...@gmx.net>.
On Monday 26 March 2007 17:51, Anthony Gardner wrote:
>  As for the $r, it's coming from Apache->request()

So, it's mp1 then. Set PerlSendHeader to On then try the approach given in my 
previous mail. I don't know for sure because I have switched to mp2 several 
years ago.

>  but we are 
> experiencing segfaults

switch to mp2. It's much more stable.

Torsten

Re: internal_redirect & ModPerlRegistr

Posted by Anthony Gardner <cy...@yahoo.co.uk>.
The script is running under ModPerlRegistry but nothing is happening. After posting this problem, I read that internal_redirect can only be called from a content handler. 
 
 So, am I right in now thinking, because my cgi script gets wrapped by a handler, it's considered a content handler? If so, why oh why isn;t it working :(
 
 As for the $r, it's coming from Apache->request() ............ but we are experiencing segfaults

Perrin Harkins <ph...@gmail.com> wrote: On 3/26/07, Anthony Gardner  wrote:
> Can I only use internal_redirect in handlers or is it possible to use it
> within a cgi script calling another cgi script?

If by "CGI script" you mean something running ModPerl::Registry, then
yes, it works fine.  If you mean a perl program called through mod_cgi
and not mod_perl, then no.  You would have to fake that with LWP or
similar.

> my $r = $self->_request_rec();

That looks pretty scary.  Where is the value of $self->_request_rec()
coming from?  If you keep a RequestRec object around and try to use it
in a later request, bad things will happen (segfaults).

- 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.