Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LocationMatch with Apache2 #200

Open
miyagawa opened this issue May 5, 2011 · 6 comments
Open

LocationMatch with Apache2 #200

miyagawa opened this issue May 5, 2011 · 6 comments

Comments

@miyagawa
Copy link
Member

miyagawa commented May 5, 2011

via email:

I encountered a problem when using Plack::Handler::Apache2 in two machines with equal apache configuration but different Plack::Handler::Apache2 versions.
In both machines there's a LocationMatch like this:

 <LocationMatch "/(andebol/videos/)">

When running in machine 1 (older version of Plack::Handler::Apache2), that has this code in the fixup_path sub:

sub fixup_path {
   my ($class, $r, $env) = @_;
   my $vpath    = $env->{SCRIPT_NAME} . ($env->{PATH_INFO} || '');
   my $location = $r->location || "/";
      $location =~ s{/$}{};
   (my $path_info = $vpath) =~ s/^\Q$location\E//;

   $env->{SCRIPT_NAME} = $location;
   $env->{PATH_INFO}   = $path_info;
}

Everything goes well when I point my browser to http://myserver.com/andebol/videos/

When trying the same LocationMatch with the newest version of Plack::Handler::Apache2, with my browser pointed to http://yserver.com/andebol/videos/ , in my application, the request_uri is just "/"
When I change the LocationMatch to this:
<LocationMatch "/(testing)|(andebol/videos/)">
The request_uri on my application is correct, /andebol/videos/, but I got this error in the apache error log:
Your request path is '/andebol/videos/' and it doesn't match your Location(Match) '/(testing)|(andebol/videos/)'. This should be due to the configuration error. See perldoc Plack::Handler::Apache2 for details.

I looked at this line ~#106:

} elsif ($path_info =~ s{^($location)/?}{/}) {
This is what happens. The "/andebol/videos" is changed to "/".
I changed this line to:
} elsif ($path_info =~ /^($location)\/?/ ) {

so that no substitution is made, and path_info keeps unchanged.

I ask if this is a bug with Plack::Handler::Apache2 or if I'm using it incorrectly.

@miyagawa
Copy link
Member Author

miyagawa commented May 5, 2011

@cho45 @clkao @ranguard Thoughts?

@miyagawa
Copy link
Member Author

miyagawa commented May 6, 2011

I think this is actually an expected behavior, since the path matches with LocationMatch and it's stripped as a SCRIPT_NAME now, and the remaining bit (which is "/") goes to the PATH_INFO. Is that right?

That said, I understand the need for the original (buggy) behavior where you can partially match the path while keeping the PATH_INFO intact, as if the app is hosted at /. Is there any easy way to work around, probably using mod_rewrite?

@nunjesus
Copy link

nunjesus commented May 6, 2011

Thank you for opening this issue.

Behind Apache I'm running Dancer, and when I try this:
http://myserver.com/andebol/videos/

This Dancer sub prints out "/".

    my ($file) = splat;
    print STDERR "file:".$file."\n";
}

But, If I change the Location match from
LocationMatch "/(andebol/videos/)"
to
LocationMatch "/(testing)/(andebol/videos/)"

Dancer prints out "/andebol/videos/" (which is what I expected it to do), but I get an error on error-log saying:
Your request path is '/andebol/videos/' and it doesn't match your Location(Match) '/(testing)|(andebol/videos/)'. This should be due to the configuration error. See perldoc Plack::Handler::Apache2 for details.

@miyagawa
Copy link
Member Author

miyagawa commented May 6, 2011

I don't understand the issue here - the LocationMatch "/(testing)/(andebol/videos/)" regexp clearly doesn't match with the request path "/andebol/videos/" or does it?

@miyagawa
Copy link
Member Author

miyagawa commented May 6, 2011

Oh, i know what is going on - your match has "/" in the left side of | but not on the right side, confusing Plack::Handler::Apache2.

<LocaitonMatch "/testing|/andebol/videos">

and that will nuke the warnings. BUT then, you'll see the original problem, where these "/andebol/videos" is stripped away from your request path, since Plack assumes that's the "base" path of your application.

@miyagawa
Copy link
Member Author

miyagawa commented May 6, 2011

See: http://cpansearch.perl.org/src/FLORA/Catalyst-Engine-Apache-1.16/lib/Catalyst/Engine/Apache.pm

if ( $self->apache->dir_config('CatalystDisableLocationMatch') ) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants