Author: dom Date: 2007-06-18 16:20:16 +0100 (Mon, 18 Jun 2007) New Revision: 1091
Modified: trunk/lib/OpenGuides/Template.pm trunk/t/15_template.t trunk/t/58_navbar_common_locales_categories.t trunk/t/59_preferences.t trunk/wiki.cgi Log: Add noheaders option, and use that in preference to black content_type arg. (fixes #220)
Modified: trunk/lib/OpenGuides/Template.pm =================================================================== --- trunk/lib/OpenGuides/Template.pm 2007-06-17 16:51:11 UTC (rev 1090) +++ trunk/lib/OpenGuides/Template.pm 2007-06-18 15:20:16 UTC (rev 1091) @@ -50,7 +50,8 @@ template => "node.tt", content_type => "text/html", cookies => $cookie, - vars => {foo => "bar"} + vars => {foo => "bar"}, + noheaders => 1 );
Returns everything you need to send to STDOUT, including the @@ -111,6 +112,9 @@ Content-Type: defaults to C<text/html> and is omitted if the C<content_type> arg is explicitly set to the blank string.
+However, what you more often need is the C<noheaders> option, +which suppresses all HTTP headers, not just the Content-Type. + The HTTP response code may be explictly set with the C<http_status> arg.
=cut @@ -187,31 +191,32 @@ $tt_vars = { %$tt_vars, %{ $args{vars} || {} } };
my $header = ""; - my %cgi_header_args;
- if ( defined $args{content_type} and $args{content_type} eq "" ) { - $cgi_header_args{'-type'} = ''; - } else { - if ( $args{content_type} ) { - $cgi_header_args{'-type'} = $args{content_type}; + unless ( $args{noheaders} ) { + my %cgi_header_args; + + if ( defined $args{content_type} and $args{content_type} eq "" ) { + $cgi_header_args{'-type'} = ''; } else { - $cgi_header_args{'-type'} = "text/html"; + if ( $args{content_type} ) { + $cgi_header_args{'-type'} = $args{content_type}; + } else { + $cgi_header_args{'-type'} = "text/html"; + } } + if ( $tt_vars->{http_charset} ) { $cgi_header_args{'-type'} .= "; charset=".$tt_vars->{http_charset}; } - # XXX should possibly not be inside this block, but retaining - # existing functionality for now. See - # http://dev.openguides.org/ticket/220 $cgi_header_args{'-cookie'} = $args{cookies}; - }
- if ( $args{http_status} ) { - $cgi_header_args{'-status'} = $args{http_status}; + if ( $args{http_status} ) { + $cgi_header_args{'-status'} = $args{http_status}; + } + + $header = CGI::header( %cgi_header_args ); }
- $header = CGI::header( %cgi_header_args ); - # vile hack my %field_vars = OpenGuides::Template->extract_metadata_vars( wiki => $args{wiki}, @@ -219,7 +224,7 @@ set_coord_field_vars => 1, metadata => {}, ); - + $tt_vars = { %field_vars, %$tt_vars };
my $output;
Modified: trunk/t/15_template.t =================================================================== --- trunk/t/15_template.t 2007-06-17 16:51:11 UTC (rev 1090) +++ trunk/t/15_template.t 2007-06-18 15:20:16 UTC (rev 1091) @@ -5,7 +5,7 @@ use OpenGuides; use OpenGuides::Template; use OpenGuides::Test; -use Test::More tests => 28; +use Test::More tests => 29;
my $config = OpenGuides::Test->make_basic_config; $config->template_path( cwd . "/t/templates" ); @@ -52,6 +52,17 @@ "Content-Type header omitted if content_type arg explicitly blank" );
$output = OpenGuides::Template->output( + wiki => $wiki, + config => $config, + template => "15_test.tt", + noheaders => 1, + http_response => 500 +); + +unlike( $output, qr/^Status: /, + "Headers omitted if noheaders arg given" ); + +$output = OpenGuides::Template->output( wiki => $wiki, config => $config, template => "15_idonotexist.tt"
Modified: trunk/t/58_navbar_common_locales_categories.t =================================================================== --- trunk/t/58_navbar_common_locales_categories.t 2007-06-17 16:51:11 UTC (rev 1090) +++ trunk/t/58_navbar_common_locales_categories.t 2007-06-18 15:20:16 UTC (rev 1091) @@ -32,7 +32,7 @@ wiki => $guide->wiki, config => $guide->config, template => "preferences.tt", - content_type => '', + noheaders => 1, vars => { not_editable => 1, show_form => 1
Modified: trunk/t/59_preferences.t =================================================================== --- trunk/t/59_preferences.t 2007-06-17 16:51:11 UTC (rev 1090) +++ trunk/t/59_preferences.t 2007-06-18 15:20:16 UTC (rev 1091) @@ -59,7 +59,7 @@ wiki => $wiki, config => $config, template => "preferences.tt", - content_type => '', + noheaders => 1, vars => { not_editable => 1, show_form => 1
Modified: trunk/wiki.cgi =================================================================== --- trunk/wiki.cgi 2007-06-17 16:51:11 UTC (rev 1090) +++ trunk/wiki.cgi 2007-06-18 15:20:16 UTC (rev 1091) @@ -302,7 +302,7 @@ template => $template, vars => $vars ); - $output_conf{content_type} = "" if $omit_header; # defaults otherwise + $output_conf{noheaders} = 1 if $omit_header; # defaults otherwise print OpenGuides::Template->output( %output_conf ); }
openguides-commits@lists.openguides.org