[Catalyst] mod_perl location handler problem

Jason Rhinelander jagerman at jagerman.com
Tue Mar 7 01:56:12 CET 2006


Hi,

I started playing with Catalyst for the first time this weekend, and I
have to say I like it very much.  That said, I've run into a minor
problem with respect to the handling of location under mod_perl.
Specifically, I have apache set up with:

<Location /foo>
    SetHandler perl-script
    PerlResponseHandler Foo
</Location>

Now, the specific problem is that when a request comes in at
http://localhost/foo - which I want to be able to do - $c->request->path
gives me "foo", instead of "" which I get for http://localhost/foo/.
(Likewise, http://localhost/foo/foo also gives "foo", but that's
supposed to happen).  I dug into Catalyst a bit more and I think found
the problem - inside Catalyst::Engine::Apache, it gets the current
location with $r->location, then appends a / if it doesn't have one:

    # set the base URI
    # base must end in a slash
    $base_path .= '/' unless ( $base_path =~ /\/$/ );

Then, in Catalyst::Request, the base path (location) is removed with:

    $path =~ s/^(\Q$location\E)?//;

That doesn't remove the location because the current uri is '/foo',
instead of the '/foo/' that the location is now set to.

A potential fix is to change these lines from:

    $path =~ s/^(\Q$location\E)?//;
    $path =~ s/^\///;

to:

    $location =~ s{/$}{};
    $path =~ s/^(\Q$location\E)?(?:\/|$)//;

which would make the handling a little more lenient and ought to fix the
problem.  On the other hand, it's entirely possible that I'm missing
something obvious - comments?

I did work around the problem by defining my own 'sub handler ($$) :
method' that fakes a new uri with $r->uri($uri . '/') if such a request
is encountered then calls SUPER::handler, and though that works it's
obviously a hack rather than a fix.


-- 
-- Jason Rhinelander



More information about the Catalyst mailing list