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

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

Files:
1 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