Changeset 1091

Show
Ignore:
Timestamp:
06/18/07 16:20:16 (16 months ago)
Author:
dom
Message:

Add noheaders option, and use that in preference to black content_type
arg. (fixes #220)

Location:
trunk
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • trunk/lib/OpenGuides/Template.pm

    r1085 r1091  
    5151                                      content_type => "text/html", 
    5252                                      cookies      => $cookie, 
    53                                       vars         => {foo => "bar"} 
     53                                      vars         => {foo => "bar"}, 
     54                                      noheaders    => 1 
    5455  ); 
    5556 
     
    111112Content-Type: defaults to C<text/html> and is omitted if the 
    112113C<content_type> arg is explicitly set to the blank string. 
     114 
     115However, what you more often need is the C<noheaders> option, 
     116which suppresses all HTTP headers, not just the Content-Type. 
    113117 
    114118The HTTP response code may be explictly set with the C<http_status> arg. 
     
    188192 
    189193    my $header = ""; 
    190     my %cgi_header_args; 
    191  
    192     if ( defined $args{content_type} and $args{content_type} eq "" ) { 
    193         $cgi_header_args{'-type'} = ''; 
    194     } else { 
    195         if ( $args{content_type} ) { 
    196             $cgi_header_args{'-type'} = $args{content_type}; 
     194 
     195    unless ( $args{noheaders} ) { 
     196        my %cgi_header_args; 
     197 
     198        if ( defined $args{content_type} and $args{content_type} eq "" ) { 
     199            $cgi_header_args{'-type'} = ''; 
    197200        } else { 
    198             $cgi_header_args{'-type'} = "text/html"; 
    199         } 
     201            if ( $args{content_type} ) { 
     202                $cgi_header_args{'-type'} = $args{content_type}; 
     203            } else { 
     204                $cgi_header_args{'-type'} = "text/html"; 
     205            } 
     206        } 
     207 
    200208        if ( $tt_vars->{http_charset} ) { 
    201209            $cgi_header_args{'-type'} .= "; charset=".$tt_vars->{http_charset}; 
    202210        } 
    203         # XXX should possibly not be inside this block, but retaining 
    204         # existing functionality for now. See 
    205         # http://dev.openguides.org/ticket/220 
    206211        $cgi_header_args{'-cookie'} = $args{cookies}; 
    207     } 
    208  
    209     if ( $args{http_status} ) { 
    210         $cgi_header_args{'-status'} = $args{http_status}; 
    211     } 
    212  
    213     $header = CGI::header( %cgi_header_args ); 
     212 
     213        if ( $args{http_status} ) { 
     214            $cgi_header_args{'-status'} = $args{http_status}; 
     215        } 
     216 
     217        $header = CGI::header( %cgi_header_args ); 
     218    } 
    214219 
    215220    # vile hack 
     
    220225                         metadata => {}, 
    221226                     ); 
    222                       
     227 
    223228    $tt_vars = { %field_vars, %$tt_vars }; 
    224229 
  • trunk/t/15_template.t

    r1040 r1091  
    66use OpenGuides::Template; 
    77use OpenGuides::Test; 
    8 use Test::More tests => 28; 
     8use Test::More tests => 29; 
    99 
    1010my $config = OpenGuides::Test->make_basic_config; 
     
    5151unlike( $output, qr/^Content-Type: text\/html/, 
    5252        "Content-Type header omitted if content_type arg explicitly blank" ); 
     53 
     54$output = OpenGuides::Template->output( 
     55    wiki          => $wiki, 
     56    config        => $config, 
     57    template      => "15_test.tt", 
     58    noheaders      => 1, 
     59    http_response => 500 
     60); 
     61 
     62unlike( $output, qr/^Status: /, 
     63        "Headers omitted if noheaders arg given" ); 
    5364 
    5465$output = OpenGuides::Template->output( 
  • trunk/t/58_navbar_common_locales_categories.t

    r1086 r1091  
    3333        config       => $guide->config, 
    3434        template     => "preferences.tt", 
    35         content_type => '', 
     35        noheaders    => 1, 
    3636        vars         => { 
    3737                          not_editable => 1, 
  • trunk/t/59_preferences.t

    r1085 r1091  
    6060        config       => $config, 
    6161        template     => "preferences.tt", 
    62         content_type => '', 
     62        noheaders    => 1, 
    6363        vars         => { 
    6464                          not_editable => 1, 
  • trunk/wiki.cgi

    r1057 r1091  
    303303            vars     => $vars 
    304304    ); 
    305     $output_conf{content_type} = "" if $omit_header; # defaults otherwise 
     305    $output_conf{noheaders} = 1 if $omit_header; # defaults otherwise 
    306306    print OpenGuides::Template->output( %output_conf ); 
    307307}