You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Drew Taylor <dt...@vialogix.com> on 2000/06/27 15:27:16 UTC
$r->path_info question
Hi all,
I am using $r->path_info in an Apache handler. The handler is set via a
Location directive:
<Location /cgi-bin/detail.pl> # Overcoming Legacy code :-)
SetHandler perl-script
PerlHandler eLogix::Images::Detail
</Location>
And is called like "/cgi-bin/detail.pl/A1234567.jpg". My question is
this: Since there is no physical filename which corresponds to the URL,
what does path_info contain? In the eagle book on page 135, when
path_info is first discussed, the example uses
$r->lookup_uri($path_info) to get the filename, which in this example is
a purely virtual tree.
I currently am using
my $filename = (split /\//, $r->path_info)[1];
but it seems like such a hack. What is the "suggested" way to get the
"A1234567.jpg" part of the above URL?
--
Drew Taylor
Vialogix Communications, Inc.
501 N. College Street
Charlotte, NC 28202
704 370 0550
http://www.vialogix.com/
Re: $r->path_info question
Posted by Drew Taylor <dt...@vialogix.com>.
David Kenzik wrote:
>
> Drew Taylor said...
> >
> > I currently am using
> >
> > my $filename = (split /\//, $r->path_info)[1];
> >
> > but it seems like such a hack. What is the "suggested" way to get the
> > "A1234567.jpg" part of the above URL?
>
> Since Apache sets path_info by scanning the physical filesystem, and since
> you are overcoming legacy calls to a script inside cgi-bin, your solution is
> probably just fine.
>
> I had a similar issue in the past:
>
> http://forum.swarthmore.edu/epigone/modperl/smumbabax
>
> As Doug mentions in that thread, $r->location might be of some assistance.
That was an interesting thread. However, I think Eric found the easiest
solution for me. This handler is very simple and if the requested file
does not pass -e, it just returns NOT_FOUND. So I guess I'll stick with
my original thinking for now.
Thanks.
--
Drew Taylor
Vialogix Communications, Inc.
501 N. College Street
Charlotte, NC 28202
704 370 0550
http://www.vialogix.com/
Re: $r->path_info question
Posted by David Kenzik <da...@kenzik.com>.
Drew Taylor said...
> Hi all,
Hi.
> I currently am using
>
> my $filename = (split /\//, $r->path_info)[1];
>
> but it seems like such a hack. What is the "suggested" way to get the
> "A1234567.jpg" part of the above URL?
Since Apache sets path_info by scanning the physical filesystem, and since
you are overcoming legacy calls to a script inside cgi-bin, your solution is
probably just fine.
I had a similar issue in the past:
http://forum.swarthmore.edu/epigone/modperl/smumbabax
As Doug mentions in that thread, $r->location might be of some assistance.
Hope this helps.
--
David S. Kenzik
david@kenzik.com - http://kenzik.com
Re: $r->path_info question
Posted by Drew Taylor <dt...@vialogix.com>.
Eric Cholet wrote:
>
> > Hi all,
> >
> > I am using $r->path_info in an Apache handler. The handler is set via a
> > Location directive:
> >
> > <Location /cgi-bin/detail.pl> # Overcoming Legacy code :-)
> > SetHandler perl-script
> > PerlHandler eLogix::Images::Detail
> > </Location>
> >
> > And is called like "/cgi-bin/detail.pl/A1234567.jpg". My question is
> > this: Since there is no physical filename which corresponds to the URL,
> > what does path_info contain? In the eagle book on page 135, when
> > path_info is first discussed, the example uses
> > $r->lookup_uri($path_info) to get the filename, which in this example is
> > a purely virtual tree.
>
> $r->path_info contains what's left of the URI after it's been mapped
> to a (virtual) file, in your case /A1234567.jpg
>
> > I currently am using
> >
> > my $filename = (split /\//, $r->path_info)[1];
>
> or you could have used
> (my $filename = $r->path_info) =~ s!^/!!;
I had not considered doing it in one pass. :-) At the risk of exposing
my newbieness, where is this form documented? (I'll admit now to not
having read the Camel book cover to cover.)
> Since you have no trailing slash in your <Location> directive,
> you get a leading / in path_info. What would be the filename if the
> request URI was /cgi-bin/detail.pl/foo/bar.jpg ? In that case
> path_info will be '/foo/bar.jpg'. Maybe what you really want
> is
> my $filename = (split /\//, $r->path_info)[-1];
Another excellent point!
So if I put a trailing / in my <Location> directive, I won't get the
leading / and path_info will be just the information I need? That's what
I really wanted, and it's a simple solution as well. Thanks! :-)
--
Drew Taylor
Vialogix Communications, Inc.
501 N. College Street
Charlotte, NC 28202
704 370 0550
http://www.vialogix.com/
Re: $r->path_info question
Posted by Eric Cholet <ch...@logilune.com>.
> Hi all,
>
> I am using $r->path_info in an Apache handler. The handler is set via a
> Location directive:
>
> <Location /cgi-bin/detail.pl> # Overcoming Legacy code :-)
> SetHandler perl-script
> PerlHandler eLogix::Images::Detail
> </Location>
>
> And is called like "/cgi-bin/detail.pl/A1234567.jpg". My question is
> this: Since there is no physical filename which corresponds to the URL,
> what does path_info contain? In the eagle book on page 135, when
> path_info is first discussed, the example uses
> $r->lookup_uri($path_info) to get the filename, which in this example is
> a purely virtual tree.
$r->path_info contains what's left of the URI after it's been mapped
to a (virtual) file, in your case /A1234567.jpg
> I currently am using
>
> my $filename = (split /\//, $r->path_info)[1];
or you could have used
(my $filename = $r->path_info) =~ s!^/!!;
> but it seems like such a hack. What is the "suggested" way to get the
> "A1234567.jpg" part of the above URL?
Since you have no trailing slash in your <Location> directive,
you get a leading / in path_info. What would be the filename if the
request URI was /cgi-bin/detail.pl/foo/bar.jpg ? In that case
path_info will be '/foo/bar.jpg'. Maybe what you really want
is
my $filename = (split /\//, $r->path_info)[-1];
whatever... it's completely up to the application to define the
semantics of path_info.
> --
> Drew Taylor
--
Eric