You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Randy Harmon <rj...@fortheweb.com> on 2002/07/10 00:28:27 UTC

RE: TransHandler called a second time after I've returned DECLINED

Rick, I hope you don't mind I've followed this up to the list.  Your reply
was *very* useful to me, and I hope others may benefit from it...since I
didn't find any archived information that was helpful and all.

> -----Original Message-----
> From: Rick Myers [mailto:rik@sumthin.nu]
> Sent: Wednesday, July 03, 2002 7:00 PM
>
> Sorry for the late reply, but I don't read the list daily.
> (Erm, or even weekly it seems. :-)
> On Jun 25, 2002 at 08:26:37 -0700, Randy Harmon wrote:

Heh, the weeks do tend to fly by.  There goes another one now.

> > I'm using a TransHandler, and having a problem where it sometimes gets
> > called twice when I don't expect it
[...]
> > On an example request for /exists/non-existent-dir/file.html,

[on the second, unexpected, TransHandler call]

> > the uri() is screwed up as /file.html.  If the request is
> > /exists/non/foo/file.html, then uri() is /foo/file.html on
> > the second (unexpected) call to my TransHandler.
>
[Rick:]
> That's an example of Apache's simplistic approach to
> matching URL's to physical disk space. I don't recall if it
> was mod_perl or Apache that actually called the TransHandler
> twice, but I suspect the latter. Here's how I worked around
> it...
>
> PerlPostReadRequestHandler AlterTrans
>
> package AlterTrans
>
> sub handler {
>     my ($r) = @_;
>     return DECLINED if $blah_blah_blah;
>     for (@{$r->get_handlers('PerlTransHandler')}) {
>         /::handler$/ or $_ .= '::handler';
>         my $rv = &{\&$_}($r);
>         $rv != DECLINED and return $rv;
>     }
>     $r->set_handlers('PerlTransHandler', undef);
>     OK;
> }
>
> Basically, what it does is calls your TransHandlers one at a
> time from the PostReadRequest phase.
>
> --rick
>
> Hmm.. maybe this is of interest?
>
> NAME
>        Apache::AlterTransChain - Alters the chaining behaviour of
[cut: rest of perldoc]

That is interesting.  I remain with trouble, in that my TransHandler relies
on things that apparently aren't available at the PostReadRequest phase -
specifically dir_config settings don't seem to be available when I use this
approach.

I was successful in using $r->set_handlers('PerlTransHandler', undef) in my
TransHandler, which apparently avoids the implicit subrequest that occurs
after I decline my TransHandler for a non-existent file like described
above.

There's still an interesting issue, where a subrequest that I *intend* to do
(while serving a site-branded error message) still has the original
filename - so I had to call $r->filename('/path/to/error_message.html')
before my subrequest would do the right thing.  But that problem is
independent of my above fix.

Thanks for the information, Rick.  Very helpful!

Randy