;
close FH;
} else {
warn "[Dispatch] Error opening error document '$str'.\n";
}
} else { # Last case is url
$url = $str;
}
if($DEBUG) {
warn "[Dispatch] Redirection for HTTP error #$errno to $url\n"
if $url;
warn "[Dispatch] Displaying message for HTTP error #$errno\n"
if $output;
}
}
# if we're under mod_perl
if(IS_MODPERL) {
my $r = $self->_r;
$r->status($errno);
# if we just want to redirect
$r->headers_out->{'Location'} = $url if $url;
return '';
} else { # else print the HTTP stuff ourselves
# stolen from http_protocol.c in Apache sources
# we don't actually use anything other than 200, 307, 400, 404 and 500
my %status_lines = (
# 100 => 'Continue',
# 101 => 'Switching Protocols',
# 102 => 'Processing',
200 => 'OK',
# 201 => 'Created',
# 202 => 'Accepted',
# 203 => 'Non-Authoritative Information',
# 204 => 'No Content',
# 205 => 'Reset Content',
# 206 => 'Partial Content',
# 207 => 'Multi-Status',
# 300 => 'Multiple Choices',
# 301 => 'Moved Permanently',
# 302 => 'Found',
# 303 => 'See Other',
# 304 => 'Not Modified',
# 305 => 'Use Proxy',
307 => 'Temporary Redirect',
400 => 'Bad Request',
# 401 => 'Authorization Required',
# 402 => 'Payment Required',
# 403 => 'Forbidden',
404 => 'Not Found',
# 405 => 'Method Not Allowed',
# 406 => 'Not Acceptable',
# 407 => 'Proxy Authentication Required',
# 408 => 'Request Time-out',
# 409 => 'Conflict',
# 410 => 'Gone',
# 411 => 'Length Required',
# 412 => 'Precondition Failed',
# 413 => 'Request Entity Too Large',
# 414 => 'Request-URI Too Large',
# 415 => 'Unsupported Media Type',
# 416 => 'Requested Range Not Satisfiable',
# 417 => 'Expectation Failed',
# 422 => 'Unprocessable Entity',
# 423 => 'Locked',
# 424 => 'Failed Dependency',
500 => 'Internal Server Error',
# 501 => 'Method Not Implemented',
# 502 => 'Bad Gateway',
# 503 => 'Service Temporarily Unavailable',
# 504 => 'Gateway Time-out',
# 505 => 'HTTP Version Not Supported',
# 506 => 'Variant Also Negotiates',
# 507 => 'Insufficient Storage',
# 510 => 'Not Extended',
);
$errno = 500 if(!exists $status_lines{$errno});
if($url) {
# somewhat mailformed header, no errors in access.log, but browsers
# display contents of $url document and old URI in address bar.
$output = "HTTP/1.0 $errno $status_lines{$errno}\n";
$output .= "Location: $url\n\n";
} else {
unless($output) {
# TODO: possibly provide more feedback in a way that
# is XSS safe. (I'm not sure that passing through the
# raw ENV variable directly is safe.)
# We tried: $ENV{REQUEST_URI}