Author: dom Date: 2009-06-20 00:12:21 +0100 (Sat, 20 Jun 2009) New Revision: 1271
Modified: trunk/Changes trunk/lib/OpenGuides.pm trunk/t/51_display_node.t Log: Return HTTP 404 status when displaying a node that doens't exist (fixes #102)
Modified: trunk/Changes =================================================================== --- trunk/Changes 2009-06-19 22:55:19 UTC (rev 1270) +++ trunk/Changes 2009-06-19 23:12:21 UTC (rev 1271) @@ -6,6 +6,7 @@ 0.65 Fix some more broken POD and add POD unit test (#268) Don't display revision info for nodes that don't exist (#193) + Return HTTP 404 status when displaying a node that doens't exist (#102)
0.64 23 February 2009 Correctly specify all build_requires (#245)
Modified: trunk/lib/OpenGuides.pm =================================================================== --- trunk/lib/OpenGuides.pm 2009-06-19 22:55:19 UTC (rev 1270) +++ trunk/lib/OpenGuides.pm 2009-06-19 23:12:21 UTC (rev 1271) @@ -273,6 +273,8 @@ metadata => $node_data{metadata} );
+ my $node_exists = $wiki->node_exists($id); + my $http_status = $node_exists ? undef : '404 Not Found'; %tt_vars = ( %tt_vars, %metadata_vars, @@ -286,7 +288,7 @@ enable_gmaps => 1, wgs84_long => $wgs84_long, wgs84_lat => $wgs84_lat, - empty_node => !$wiki->node_exists($id) + empty_node => !$node_exists );
# Hide from search engines if showing a specific version. @@ -308,6 +310,7 @@ id => $id, template => "node.tt", tt_vars => %tt_vars, + http_status => $http_status ); return $output if $return_output; print $output; @@ -363,6 +366,7 @@ id => $id, template => "home_node.tt", tt_vars => %tt_vars, + http_status => $http_status ); return $output if $return_output; print $output; @@ -372,6 +376,7 @@ id => $id, template => "node.tt", tt_vars => %tt_vars, + http_status => $http_status ); return $output if $return_output; print $output; @@ -2251,12 +2256,13 @@ sub process_template { my ($self, %args) = @_; my %output_conf = ( - wiki => $self->wiki, - config => $self->config, - node => $args{id}, - template => $args{template}, - vars => $args{tt_vars}, - cookies => $args{cookies}, + wiki => $self->wiki, + config => $self->config, + node => $args{id}, + template => $args{template}, + vars => $args{tt_vars}, + cookies => $args{cookies}, + http_status => $args{http_status} ); if ( $args{content_type} ) { $output_conf{content_type} = $args{content_type};
Modified: trunk/t/51_display_node.t =================================================================== --- trunk/t/51_display_node.t 2009-06-19 22:55:19 UTC (rev 1270) +++ trunk/t/51_display_node.t 2009-06-19 23:12:21 UTC (rev 1271) @@ -13,7 +13,7 @@ plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; }
-plan tests => 18; +plan tests => 19;
Wiki::Toolkit::Setup::SQLite::cleardb( { dbname => "t/node.db" } ); Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } ); @@ -120,3 +120,4 @@ "bogus revision number doesn't show up" ); unlike( $output, qr{\QLast edited}, "bogus last edited doesn't show up" ); +like ( $output, qr{404 Not Found}, "404 status for empty node" );