Skip to content

Commit

Permalink
Item2549: preserve REDIRECT_STATUS, so custom error messages work as …
Browse files Browse the repository at this point in the history
…exected

git-svn-id: http://svn.foswiki.org/trunk/ModPerlEngineContrib@5915 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
GilmarSantosJr authored and GilmarSantosJr committed Jan 3, 2010
1 parent 62d9ddb commit f706065
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions ModPerlEngineContrib/lib/Foswiki/Engine/Apache.pm
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ use Foswiki::Request ();
use Foswiki::Request::Upload ();
use Foswiki::Response ();
use File::Spec ();
use Assert;

sub run {
my $this = $Foswiki::engine;
Expand Down Expand Up @@ -208,9 +209,21 @@ sub finalizeUploads {
sub finalizeHeaders {
my ( $this, $res, $req ) = @_;
$this->SUPER::finalizeHeaders( $res, $req );
my ($status) = ( $res->status || "200" ) =~ /^(\d\d\d)/o;

$this->{r}->status( $res->status || 200 );
# If REDIRECT_STATUS is present, preserve it. See Foswikitask:Item2549
# and http://httpd.apache.org/docs/2.2/en/custom-error.html#custom
my $status;
if (defined $ENV{REDIRECT_STATUS}) {
$status = $ENV{REDIRECT_STATUS};
}
elsif (defined $res->status && $res->status =~ /^\s*(\d{3})/o) {
$status = $1;
}
else {
$status = 200;
}
$this->{r}->status($status);

while ( my ( $header, $value ) = each %{ $res->headers } ) {
if ( lc($header) eq 'content-type' ) {
$this->{r}->content_type($value);
Expand All @@ -228,7 +241,7 @@ sub finalizeHeaders {
$this->{r}->err_headers_out->add( $header => $_ );
}
}
else {
elsif ( lc($header) ne 'status' ) {
foreach ( ref($value) eq 'ARRAY' ? @$value : ($value) ) {
$this->{r}->headers_out->add( $header => $_ );
}
Expand Down

0 comments on commit f706065

Please sign in to comment.