Changeset 1054

Show
Ignore:
Timestamp:
06/10/07 14:45:21 (18 months ago)
Author:
dom
Message:

Add support in output routine for specifying HTTP status code (see #102)

Location:
trunk
Files:
1 added
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/MANIFEST

    r1050 r1054  
    115115t/48_google_analytics.t 
    116116t/49_custom_header.t 
     117t/50_http_response_codes.t 
    117118t/51_display_node.t 
    118119t/52_display_diffs.t 
  • trunk/lib/OpenGuides/Template.pm

    r1047 r1054  
    109109Content-Type: defaults to C<text/html> and is omitted if the 
    110110C<content_type> arg is explicitly set to the blank string. 
     111 
     112The HTTP response code may be explictly set with the C<http_status> arg. 
    111113 
    112114=cut 
     
    181183 
    182184    my $header = ""; 
    183     unless ( defined $args{content_type} and $args{content_type} eq "" ) { 
    184         my $content_type; 
    185         if ($args{content_type}) { 
    186             $content_type = $args{content_type}; 
     185    my %cgi_header_args; 
     186 
     187    if ( defined $args{content_type} and $args{content_type} eq "" ) { 
     188        $cgi_header_args{'-type'} = ''; 
     189    } else { 
     190        if ( $args{content_type} ) { 
     191            $cgi_header_args{'-type'} = $args{content_type}; 
    187192        } else { 
    188             $content_type = "text/html"; 
    189         } 
    190         if ($tt_vars->{http_charset}) { 
    191             $content_type .= "; charset=".$tt_vars->{http_charset}; 
    192         } 
    193         $header = CGI::header( -type => $content_type, -cookie => $args{cookies} ); 
    194     } 
     193            $cgi_header_args{'-type'} = "text/html"; 
     194        } 
     195        if ( $tt_vars->{http_charset} ) { 
     196            $cgi_header_args{'-type'} .= "; charset=".$tt_vars->{http_charset}; 
     197        } 
     198        # XXX should possibly not be inside this block, but retaining 
     199        # existing functionality for now. See 
     200        # http://dev.openguides.org/ticket/220 
     201        $cgi_header_args{'-cookie'} = $args{cookies}; 
     202    } 
     203 
     204    if ( $args{http_status} ) { 
     205        $cgi_header_args{'-status'} = $args{http_status}; 
     206    } 
     207 
     208    $header = CGI::header( %cgi_header_args ); 
    195209 
    196210    # vile hack