You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by John ORourke <jo...@o-rourke.org> on 2008/06/10 09:41:40 UTC

return value for response handler

Hi folks,

I had a bug with an interesting side effect which I want to understand.

I wanted to redirect the user's browser, and in my response handler I 
was setting $r->status(302) but returning Apache2::Const::OK instead of 
the correct Apache2::Const::DONE.

This caused Apache to perform an internal redirect.  Can someone explain 
what was happening in terms of handlers and subrequests or point me to 
the right doc page?

thanks
John


Re: return value for response handler

Posted by John ORourke <jo...@o-rourke.org>.
Geoffrey Young wrote:
>>> I wanted to redirect the user's browser, and in my response handler I
>>> was setting $r->status(302) but returning Apache2::Const::OK instead of
>>> the correct Apache2::Const::DONE.
> return Apache2::Const::REDIRECT

Unfortunately I can't easily do that here - I have plug-in modules which 
could return any HTTP status, and then some post-processing which makes 
use of the value of $r->status.  I handle ErrorDocument properly though 
by checking for a non-200 status before modifying it.  Then later I 
simply return OK or DONE depending on wether $r->status eq '200' or 
not.  I suppose I could just return ($r->status() eq '200)?OK:$r->status()

Re-reading the above, I suspect I can improve it a little.

>
> and I explain the internal mechanism here
>
> http://markmail.org/message/hsxqvr37pdvqolgr

That's filled in the gaps, many thanks.

John


Re: return value for response handler

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

Torsten Foertsch wrote:
> On Tue 10 Jun 2008, John ORourke wrote:
>> I had a bug with an interesting side effect which I want to understand.
>>
>> I wanted to redirect the user's browser, and in my response handler I
>> was setting $r->status(302) but returning Apache2::Const::OK instead of
>> the correct Apache2::Const::DONE.

return Apache2::Const::REDIRECT

>>
>> This caused Apache to perform an internal redirect.  Can someone explain
>> what was happening in terms of handlers and subrequests or point me to
>> the right doc page?
> 
> This is just a guess. So it may be completely wrong. But good old CGI allows 
> you to send "Status: 200" along with a Location header to perform an internal 
> redirect.
> 
> mod_perl does the same if the perl-script handler is used and PerlOptions 
> +ParseHeaders. So I'd dig in that direction if that matches your setup. 
> Otherwise it is probably an Apache thing.
> 
> If you find out what it was tell me, please.

http://www.mail-archive.com/modperl@perl.apache.org/msg04263.html

this thread mentions it a few times

http://www.mail-archive.com/modperl@apache.org/msg36041.html

and I explain the internal mechanism here

http://markmail.org/message/hsxqvr37pdvqolgr

and I know I explained this at length dev@ in at least one drawn out 
occasion, but I can't find it at the moment.

HTH

--Geoff

Re: return value for response handler

Posted by Torsten Foertsch <to...@gmx.net>.
On Tue 10 Jun 2008, John ORourke wrote:
> I had a bug with an interesting side effect which I want to understand.
>
> I wanted to redirect the user's browser, and in my response handler I
> was setting $r->status(302) but returning Apache2::Const::OK instead of
> the correct Apache2::Const::DONE.
>
> This caused Apache to perform an internal redirect.  Can someone explain
> what was happening in terms of handlers and subrequests or point me to
> the right doc page?

This is just a guess. So it may be completely wrong. But good old CGI allows 
you to send "Status: 200" along with a Location header to perform an internal 
redirect.

mod_perl does the same if the perl-script handler is used and PerlOptions 
+ParseHeaders. So I'd dig in that direction if that matches your setup. 
Otherwise it is probably an Apache thing.

If you find out what it was tell me, please.

Torsten

--
Need professional mod_perl support?
Just hire me: torsten.foertsch@gmx.net