Ignore:
Timestamp:
01/03/10 13:12:10 (2 years ago)
Author:
GilmarSantosJr
Message:

Item2549: preserve REDIRECT_STATUS, so custom error messages work as exected

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ModPerlEngineContrib/lib/Foswiki/Engine/Apache.pm

    r4569 r5915  
    7878use Foswiki::Response        (); 
    7979use File::Spec               (); 
     80use Assert; 
    8081 
    8182sub run { 
     
    209210    my ( $this, $res, $req ) = @_; 
    210211    $this->SUPER::finalizeHeaders( $res, $req ); 
    211     my ($status) = ( $res->status || "200" ) =~ /^(\d\d\d)/o; 
    212  
    213     $this->{r}->status( $res->status || 200 ); 
     212 
     213    # If REDIRECT_STATUS is present, preserve it. See Foswikitask:Item2549 
     214    # and http://httpd.apache.org/docs/2.2/en/custom-error.html#custom 
     215    my $status; 
     216    if (defined $ENV{REDIRECT_STATUS}) { 
     217        $status = $ENV{REDIRECT_STATUS}; 
     218    } 
     219    elsif (defined $res->status && $res->status =~ /^\s*(\d{3})/o) { 
     220        $status = $1; 
     221    } 
     222    else { 
     223        $status = 200; 
     224    } 
     225    $this->{r}->status($status); 
     226 
    214227    while ( my ( $header, $value ) = each %{ $res->headers } ) { 
    215228        if ( lc($header) eq 'content-type' ) { 
     
    229242            } 
    230243        } 
    231         else { 
     244        elsif ( lc($header) ne 'status' ) { 
    232245            foreach ( ref($value) eq 'ARRAY' ? @$value : ($value) ) { 
    233246                $this->{r}->headers_out->add( $header => $_ ); 
Note: See TracChangeset for help on using the changeset viewer.