You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Clayton Mitchell <cm...@atgi.net> on 2000/10/11 21:54:23 UTC
Handler is preventing redirects on missing trailing / ?
I installed a handler as such:
httpsd.conf:
-----------------
PerlModule Tofu::Tofuhandler
<Location /userfiles >
SetHandler perl-script
PerlHandler Tofu::Tofuhandler
</Location>
<Location />
AddHandler perl-script *.html
PerlHandler Tofu::Tofuhandler
</Location>
I then noticed that URI's of directories lacking a trailing '/' were not
being redirected in the browser and so relative links started to break.
As a w/o I installed a TransHandler listed below to modify the URI. It
seems like I am re-inventing the wheel here and so I assume I did something
wrong to get to this point?
Thanks for any advice.
package Tofu::Tofugruff;
#use Apache::Constants qw(:common);
use Apache::Constants qw(:response);
use strict;
sub handler {
my $r = shift;
my $f = $r->document_root.$r->uri;
my $uri = $r->uri;
if ( -d $f && $f !~/.*\/$/ ) {
# A directory that doesn't end in a '/'
$uri.='/'; # fix it
$r->err_header_out("Pragma", "no-cache");
$r->header_out("Location" => $uri );
$r->status(REDIRECT);
return DECLINED;
}
return DECLINED;
}
1;
__END__
RE: DBI / Postgres Intermittent Problem
Posted by Rajit Singh <si...@studychoice.com>.
Hi,
Thanks for those who responded to my request.
In response to something someone suggested - when i tried using Apache::DBI - there
was no difference whether or not I was using it.
I set up a new Apache/mod_perl installation to see if the problem stayed.
My old set up was mod_perl 1.21 + Apache 1.3.9 + SSL + HTML::Embperl + perl 5.00503
New set up : mod_perl 1.24 + Apache 1.3.12 + HTML::Embperl + perl 5.6
DBI on both was most recent version
After much hassle I got it all working... and - wait for it. I didn't get the
intermittent problem I've been getting!
I hammered it - I ran ab -n 100 -c 100 and it flew through without a single Internal
Server Error.
I sat hitting reload on Netscape to try and catch it out - but it was solid.
I was running the old Apache SSL installation at the same time on the same machine -
both were running of the same .epl scripts and db.
so I added the 's' after http and tried hammering again. But dammit... the problems
had disappeared from here too. unfortunately I couldn't run ab as it doesn't seem to
support https.
Looking back, I had solid reason to believe this intermittent thing was occurring
with MySQL at my old place because of various signs.
But it's possible with the problem i've had with postgres, it was occurring because
it was reloading the wrong page from the cache. I've no idea why that would happen -
but there's been no problem from either webserver since I set my cache to 0bytes
mem/disk.
So until the problem rears its head again... I'll be keeping quiet.
Rajit
Re: Handler is preventing redirects on missing trailing / ?
Posted by "Randal L. Schwartz" <me...@stonehenge.com>.
>>>>> "darren" == darren chamberlain <da...@boston.com> writes:
darren> Clayton Mitchell (cmitchell@atgi.net) said something to this effect:
>> I then noticed that URI's of directories lacking a trailing '/' were not
>> being redirected in the browser and so relative links started to break.
darren> In your handler subroutine, do something like:
darren> return DECLINED if ($r->content_type =~ /directory$/i);
darren> or
darren> return DECLINED if (-d $r->filename);
darren> HTML::Mason has this problem; Locations handled by Mason are all given to
darren> the default handler subroutine, which needs to decline directory requests.
I stole the code for Stonehenge::Pictures partially from some stuff
I saw in the Eagle book, but here's my current meme on that:
use Apache::Constants qw(:common DIR_MAGIC_TYPE);
...
sub handler {
$R = shift;
$URI = $R->uri;
...
if ($R->content_type eq DIR_MAGIC_TYPE) {
return handle_directory();
} else {
return handle_file();
}
...
sub handle_directory {
## if non-slash URL, send external redirect via mod_dir:
return DECLINED unless $URI =~ /\/$/;
...
So, I first see if content_type is DIR_MAGIC_TYPE, and then
if it doesn't also end in a slash, I decline, and the nice mod_dir
does all the external redirecting stuff.
(Stonehenge::Pictures is at
<http://www.stonehenge.com/merlyn/WebTechniques/col41.html>.)
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<me...@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
Re: Handler is preventing redirects on missing trailing / ?
Posted by darren chamberlain <da...@boston.com>.
Clayton Mitchell (cmitchell@atgi.net) said something to this effect:
> I then noticed that URI's of directories lacking a trailing '/' were not
> being redirected in the browser and so relative links started to break.
In your handler subroutine, do something like:
return DECLINED if ($r->content_type =~ /directory$/i);
or
return DECLINED if (-d $r->filename);
HTML::Mason has this problem; Locations handled by Mason are all given to
the default handler subroutine, which needs to decline directory requests.
(darren)
> As a w/o I installed a TransHandler listed below to modify the URI. It
> seems like I am re-inventing the wheel here and so I assume I did something
> wrong to get to this point?
> Thanks for any advice.
>
>
> package Tofu::Tofugruff;
>
> #use Apache::Constants qw(:common);
> use Apache::Constants qw(:response);
>
> use strict;
>
>
> sub handler {
> my $r = shift;
> my $f = $r->document_root.$r->uri;
> my $uri = $r->uri;
> if ( -d $f && $f !~/.*\/$/ ) {
> # A directory that doesn't end in a '/'
> $uri.='/'; # fix it
> $r->err_header_out("Pragma", "no-cache");
> $r->header_out("Location" => $uri );
> $r->status(REDIRECT);
> return DECLINED;
> }
> return DECLINED;
> }
>
> 1;
> __END__
>
--
I tended to place my wife under a pedestal.
-- Woody Allen
Re: Handler is preventing redirects on missing trailing / ?
Posted by Doug MacEachern <do...@covalent.net>.
On Wed, 11 Oct 2000, Clayton Mitchell wrote:
> I then noticed that URI's of directories lacking a trailing '/' were not
> being redirected in the browser and so relative links started to break.
since your PerlHandler is handling the directory, you need to manage that.
mod_autoindex and mod_dir both do it themselves, in different ways, here's
mod_dir:
if (r->uri[0] == '\0' || r->uri[strlen(r->uri) - 1] != '/') {
char *ifile;
if (r->args != NULL)
ifile = ap_pstrcat(r->pool, ap_escape_uri(r->pool, r->uri),
"/", "?", r->args, NULL);
else
ifile = ap_pstrcat(r->pool, ap_escape_uri(r->pool, r->uri),
"/", NULL);
ap_table_setn(r->headers_out, "Location",
ap_construct_url(r->pool, ifile, r));
return HTTP_MOVED_PERMANENTLY;
}