You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axkit-dev@xml.apache.org by ma...@sergeant.org on 2006/08/24 02:05:12 UTC
[SVN] [116] Move redirect code to the fixup stage
Revision: 116
Author: matt
Date: 2006-08-24 00:04:48 +0000 (Thu, 24 Aug 2006)
Log Message:
-----------
Move redirect code to the fixup stage
Modified Paths:
--------------
trunk/plugins/aio/uri_to_file
trunk/plugins/uri_to_file
Modified: trunk/plugins/aio/uri_to_file
===================================================================
--- trunk/plugins/aio/uri_to_file 2006-08-24 00:03:58 UTC (rev 115)
+++ trunk/plugins/aio/uri_to_file 2006-08-24 00:04:48 UTC (rev 116)
@@ -101,9 +101,7 @@
my $config = $self->config;
IO::AIO::aio_stat($path, sub {
- $self->log(LOGINFO, "aio_stat($path) returned ($_[0])");
- if ($_[0]) {
- # error (usually file didn't exist).
+ if (!-e _) {
while ($path =~ /\// && !-f $path) {
$path =~ s/(\/[^\/]*)$//;
$path_info = $1 . $path_info;
@@ -119,13 +117,7 @@
}
}
elsif (-d _) {
- # URI didn't end in a slash - need to redirect
- if ($original_uri !~ /\/$/) {
- $self->log(LOGINFO, "redirecting to $original_uri/$removed");
- $client->headers_out->header('Location', "$original_uri/$removed");
- $client->notes('uri_to_file_retcode', REDIRECT);
- return;
- }
+ $client->notes('is_dir', 1);
if (my $dirindex = $config->notes($self->plugin_name . '::dirindex')) {
my $filepath = catfile($path, $dirindex);
$path = $filepath if -f $filepath;
@@ -150,6 +142,24 @@
# This allows us to return REDIRECT above
sub hook_uri_translation2 {
my $self = shift;
- $self->log(LOGDEBUG, "uri_to_file continuation finished");
return $self->client->notes('uri_to_file_retcode');
}
+
+sub hook_fixup {
+ my $self = shift;
+
+ return DECLINED unless $self->client->notes('is_dir');
+
+ my $uri = $self->client->headers_in->request_uri;
+
+ no warnings 'uninitialized';
+
+ if ($uri =~ s/^([^\?]*)(?<!\/)(\?.*)?$/$1\/$2/) {
+ # send redirect
+ $self->log(LOGINFO, "redirect to $uri");
+ $self->client->headers_out->header('Location', "$uri");
+ return REDIRECT;
+ }
+
+ return DECLINED;
+}
Modified: trunk/plugins/uri_to_file
===================================================================
--- trunk/plugins/uri_to_file 2006-08-24 00:03:58 UTC (rev 115)
+++ trunk/plugins/uri_to_file 2006-08-24 00:04:48 UTC (rev 116)
@@ -84,12 +84,7 @@
my $path_info = '';
if (-d $path) {
- if ($original_uri !~ /\/$/) {
- # send redirect
- $self->log(LOGINFO, "redirect to $original_uri/$removed");
- $self->client->headers_out->header('Location', "$original_uri/$removed");
- return REDIRECT;
- }
+ $self->client->notes('is_dir', 1);
if (my $dirindex = $self->config->notes($self->plugin_name . '::dirindex')) {
my $filepath = catfile($path, $dirindex);
$path = $filepath if -f $filepath;
@@ -118,3 +113,23 @@
return DECLINED;
}
+
+# fixup directory requests to have a / on the end.
+sub hook_fixup {
+ my $self = shift;
+
+ return DECLINED unless $self->client->notes('is_dir');
+
+ my $uri = $self->client->headers_in->request_uri;
+
+ no warnings 'uninitialized';
+
+ if ($uri =~ s/^([^\?]*)(?<!\/)(\?.*)?$/$1\/$2/) {
+ # send redirect
+ $self->log(LOGINFO, "redirect to $uri");
+ $self->client->headers_out->header('Location', "$uri");
+ return REDIRECT;
+ }
+
+ return DECLINED;
+}