} else {
$input = new CGI;
}
+my $cgi_error = $input->cgi_error;
+if ($cgi_error) {
+ fatal_error( "Error parsing the request", $cgi_error );
+}
+
my $pet0 = new Benchmark;
my $tet0 = new Benchmark;
my $template = new Packages::Template( $TEMPLATEDIR, $opts{format}, { lang => $opts{lang}, charset => $charset, debug => ( DEBUG ? $opts{debug} : 0 ) }, ( $CACHEDIR ? { COMPILE_DIR => $CACHEDIR } : {} ) );
+unless (-e "$TEMPLATEDIR/$opts{format}/${what_to_do}.tmpl") {
+ fatal_error( "requested format not available for this document",
+ "405 requested format not available");
+}
+
my (%html_header, %page_content);
unless (@Packages::CGI::fatal_errors) {
no strict 'refs';
$page_content{quotemeta} = sub { return quotemeta($_[0]) };
$page_content{string2id} = sub { return &Packages::CGI::string2id(@_) };
-print $input->header(-charset => $charset, -type => get_mime($opts{format}) );
-
-#use Data::Dumper;
-#print '<pre>'.Dumper(\%ENV, \%html_header, \%page_content, get_all_messages()).'</pre>';
-
unless (@Packages::CGI::fatal_errors) {
-print $template->page( $what_to_do, { %page_content, %{ get_all_messages() } } );
+ print $input->header(-charset => $charset, -type => get_mime($opts{format}) );
+ #use Data::Dumper;
+ #print '<pre>'.Dumper(\%ENV, \%html_header, \%page_content, get_all_messages()).'</pre>';
+ print $template->page( $what_to_do, { %page_content, %{ get_all_messages() } } );
+ my $tet1 = new Benchmark;
+ my $tetd = timediff($tet1, $tet0);
+ print $template->trailer( undef, undef, undef, $tetd );
+} elsif ($Packages::CGI::http_code) {
+ print $input->header( -charset => $charset, -status => $Packages::CGI::http_code );
} else {
-print $template->error_page( get_all_messages() );
+ # We currently have only an error page in html
+ # so no format support here
+ print $input->header( -charset => $charset );
+ print $template->error_page( get_all_messages() );
+ print $template->trailer();;
}
-my $tet1 = new Benchmark;
-my $tetd = timediff($tet1, $tet0);
-
-my $trailer = $template->trailer( undef, undef, undef, $tetd );
-print $trailer;
# vim: ts=8 sw=4
'txt.gz' => 'text/plain',
html => 'text/html',
rss => 'application/rss+xml',
+ rfc822 => 'text/plain',
);
sub get_mime {
}
our (@fatal_errors, @errors, @debug, @msgs, @hints, @notes);
+our $http_code;
sub reset {
@fatal_errors = @errors = @debug = @msgs = @hints = @notes = ();
+ $http_code = 200;
}
sub fatal_error {
push @fatal_errors, $_[0];
+ $http_code = $_[1] if $_[1];
}
sub error {
push @errors, $_[0];