You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by "Michael L. Artz" <dr...@october29.net> on 2004/02/07 07:03:53 UTC

Passing data to a custom_response

I was wondering if it was possible to pass data from a handler to a 
custom_response declared handler within apache2/mod_perl2.  I am putting 
a custom_response on the the HTTP_FORBIDDEN return code to direct the 
user to a login page (custom_response(Apache::HTTP_FORBIDDEN, 
'login.pl')), so if the user/pass doesn't pass muster in the 
authentication phase, or if they aren't allow to view the page because 
their permissions aren't high enough in the authorization phase, the 
handler returns a custom page telling the user to login or what their 
error was.  I'd like to tell them why they are at the custom response 
page (i.e. they are required to login or they entered and invalid 
user/pass).  I've tried using notes and pnotes that I set in the 
authentication and authorization phases, but it looks like the 
custom_response actually creates a new request (or is it a subrequest?), 
and the notes and pnotes that I set aren't being seen by the 
ModPerl::Registry login page.  Is there any way to pass data to a 
custom_response defined page?  Any better ideas on how to handle this, 
other than putting it in a get request and redirecting?

Thanks
-Mike


-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: Passing data to a custom_response

Posted by Geoffrey Young <ge...@modperlcookbook.org>.
> I've tried using notes and pnotes that I set in the
> authentication and authorization phases, but it looks like the
> custom_response actually creates a new request (or is it a subrequest?),
> and the notes and pnotes that I set aren't being seen by the
> M

you're on the right track here.  custom_responses are subrequests, so you
can access the notes via

$r->prev->notes

be careful, though - that will blow up if $r->prev is undefined, which it
will be if your error page is somehow accessed directly.

> Any better ideas on how to handle this,
> other than putting it in a get request and redirecting?

you could also stash data in the query string

$r->custom_response(HTTP_FORBIDDEN, "/foo/?why+you+were+sent+here");

then get at it directly via $r->args.

see recipe 8.6 in the mod_perl developer's cookbook for more of this kind of
thing.

HTH

--Geoff


-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html