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/16 23:17:33 UTC
[SVN] [98] Send a 404 if nothing served the request
Revision: 98
Author: matt
Date: 2006-08-16 21:17:15 +0000 (Wed, 16 Aug 2006)
Log Message:
-----------
Send a 404 if nothing served the request
More work on uri_to_file (hope I've got it right THIS time! haha)
Modified Paths:
--------------
trunk/lib/AxKit2/Client.pm
trunk/lib/AxKit2/Constants.pm
trunk/lib/AxKit2/HTTPHeaders.pm
trunk/plugins/serve_file
trunk/plugins/uri_to_file
Modified: trunk/lib/AxKit2/Client.pm
===================================================================
--- trunk/lib/AxKit2/Client.pm 2006-08-16 20:44:10 UTC (rev 97)
+++ trunk/lib/AxKit2/Client.pm 2006-08-16 21:17:15 UTC (rev 98)
@@ -197,7 +197,21 @@
my $self = shift;
my ($ret, $out) = $self->run_hooks('response', @_);
if ($ret == DECLINED) {
- return 1;
+ $self->headers_out->code(NOT_FOUND);
+ $self->headers_out->header('Content-Type' => 'text/html; charset=UTF-8');
+ $self->send_http_headers;
+ my $uri = $self->headers_in->uri;
+ $self->write(<<EOT);
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
+<HTML><HEAD>
+<TITLE>404 Not Found</TITLE>
+</HEAD><BODY>
+<H1>Not Found</H1>
+The requested URL $uri was not found on this server.<P>
+<HR>
+</BODY></HTML>
+EOT
+ return;
}
elsif ($ret == OK) {
return 1;
Modified: trunk/lib/AxKit2/Constants.pm
===================================================================
--- trunk/lib/AxKit2/Constants.pm 2006-08-16 20:44:10 UTC (rev 97)
+++ trunk/lib/AxKit2/Constants.pm 2006-08-16 21:17:15 UTC (rev 98)
@@ -21,6 +21,10 @@
# return codes
my %return_codes = (
OK => 200,
+ NOT_MODIFIED => 304,
+ BAD_REQUEST => 400,
+ FORBIDDEN => 403,
+ NOT_FOUND => 404,
SERVER_ERROR => 500,
DECLINED => 909,
DONE => 910,
Modified: trunk/lib/AxKit2/HTTPHeaders.pm
===================================================================
--- trunk/lib/AxKit2/HTTPHeaders.pm 2006-08-16 20:44:10 UTC (rev 97)
+++ trunk/lib/AxKit2/HTTPHeaders.pm 2006-08-16 21:17:15 UTC (rev 98)
@@ -257,6 +257,7 @@
sub request_uri {
my AxKit2::HTTPHeaders $self = shift;
+ @_ and $self->{uri} = shift;
return $self->{uri};
}
Modified: trunk/plugins/serve_file
===================================================================
--- trunk/plugins/serve_file 2006-08-16 20:44:10 UTC (rev 97)
+++ trunk/plugins/serve_file 2006-08-16 21:17:15 UTC (rev 98)
@@ -37,29 +37,13 @@
my $file = $hd->filename;
$self->log(LOGINFO, "Serving file: $file");
if (open(my $fh, $file)) {
- $self->client->write("HTTP/1.1 200 OK
-Date: Mon, 24 Jul 2006 23:59:39 GMT
-Server: Apache/1.3.33 (Darwin)
-Content-Type: $ct
-
-");
+ $hd->header('Content-Type', $ct);
+ $self->client->send_http_headers;
+
local $/;
$self->client->write(<$fh>);
+ return OK;
}
- else {
- # this should be a 404, probably
- $self->client->write("HTTP/1.1 200 OK
-Date: Mon, 24 Jul 2006 23:59:39 GMT
-Server: Apache/1.3.33 (Darwin)
-Content-Type: text/html
-
-<HTML>
-<HEAD><TITLE>Test Page</TITLE></HEAD>
-<BODY>
-<H1>Testing: $file</H1>
-</BODY>
-</HTML>");
- }
}
return DECLINED;
Modified: trunk/plugins/uri_to_file
===================================================================
--- trunk/plugins/uri_to_file 2006-08-16 20:44:10 UTC (rev 97)
+++ trunk/plugins/uri_to_file 2006-08-16 21:17:15 UTC (rev 98)
@@ -61,6 +61,10 @@
$uri =~ s/^\Q$root// || die "$uri did not match config path $root";
my $path = canonpath(catfile($self->config->docroot, $uri));
+ $path .= '/' if $uri =~ /\/$/; # canonpath will strip a trailing slash
+
+ my $path_info = '';
+
if (-d $path) {
if ($original_uri !~ /\/$/) {
# send redirect
@@ -86,14 +90,24 @@
$path = $filepath if -f $filepath;
}
}
-
- my $path_info = '';
- while (!-e $path) {
- $path =~ s/(\/[^\/]*)$//;
- $path_info = $1 . $path_info;
+ else {
+ while ($path =~ /\// && !-f $path) {
+ $path =~ s/(\/[^\/]*)$//;
+ $path_info = $1 . $path_info;
+ }
+ if ($path_info && -f _) {
+ $hd->path_info($path_info);
+ substr($original_uri, 0 - length($path_info)) = '';
+ $hd->request_uri($original_uri);
+ }
+ else {
+ $path .= $path_info;
+ $hd->path_info('');
+ }
}
- $hd->path_info($path_info);
+ $self->log(LOGDEBUG, "Translated $uri to $path" .
+ ($path_info ? " (path info: $path_info)" : ""));
$hd->filename($path);