Skip to content

Commit

Permalink
Patch from Steve Hay to make CGI::Carp's error messages appear on MSI…
Browse files Browse the repository at this point in the history
…E browsers.
  • Loading branch information
lstein committed Apr 11, 2003
1 parent 7522eb6 commit d20f76e
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 51 deletions.
107 changes: 57 additions & 50 deletions CGI/Carp.pm
Expand Up @@ -415,69 +415,76 @@ sub warningsToBrowser {

# headers
sub fatalsToBrowser {
my($msg) = @_;
$msg=~s/&/&/g;
$msg=~s/>/>/g;
$msg=~s/</&lt;/g;
$msg=~s/\"/&quot;/g;
my($wm) = $ENV{SERVER_ADMIN} ?
qq[the webmaster (<a href="mailto:$ENV{SERVER_ADMIN}">$ENV{SERVER_ADMIN}</a>)] :
"this site's webmaster";
my ($outer_message) = <<END;
my($msg) = @_;
$msg=~s/&/&amp;/g;
$msg=~s/>/&gt;/g;
$msg=~s/</&lt;/g;
$msg=~s/\"/&quot;/g;
my($wm) = $ENV{SERVER_ADMIN} ?
qq[the webmaster (<a href="mailto:$ENV{SERVER_ADMIN}">$ENV{SERVER_ADMIN}</a>)] :
"this site's webmaster";
my ($outer_message) = <<END;
For help, please send mail to $wm, giving this error message
and the time and date of the error.
END
;
my $mod_perl = exists $ENV{MOD_PERL};
print STDOUT "Content-type: text/html\n\n"
unless $mod_perl;

warningsToBrowser(1); # emit warnings before dying

if ($CUSTOM_MSG) {
if (ref($CUSTOM_MSG) eq 'CODE') {
&$CUSTOM_MSG($msg); # nicer to perl 5.003 users
return;
} else {
$outer_message = $CUSTOM_MSG;
}
;
my $mod_perl = exists $ENV{MOD_PERL};
print STDOUT "Content-type: text/html\n\n"
unless $mod_perl;

warningsToBrowser(1); # emit warnings before dying

if ($CUSTOM_MSG) {
if (ref($CUSTOM_MSG) eq 'CODE') {
&$CUSTOM_MSG($msg); # nicer to perl 5.003 users
return;
} else {
$outer_message = $CUSTOM_MSG;
}
}

my $mess = <<END;
my $mess = <<END;
<h1>Software error:</h1>
<pre>$msg</pre>
<p>
$outer_message
</p>
END
;

if ($mod_perl) {
require mod_perl;
if ($mod_perl::VERSION >= 1.99) {
$mod_perl = 2;
require Apache::RequestRec;
require Apache::RequestIO;
require Apache::RequestUtil;
require APR::Pool;
require ModPerl::Util;
require Apache::Response;
}
my $r = Apache->request;
# If bytes have already been sent, then
# we print the message out directly.
# Otherwise we make a custom error
# handler to produce the doc for us.
if ($r->bytes_sent) {
$r->print($mess);
$mod_perl == 2 ? ModPerl::Util::exit(0) : $r->exit;
} else {
$r->status(500);
$r->custom_response(500,$mess);
}
;

if ($mod_perl) {
require mod_perl;
if ($mod_perl::VERSION >= 1.99) {
$mod_perl = 2;
require Apache::RequestRec;
require Apache::RequestIO;
require Apache::RequestUtil;
require APR::Pool;
require ModPerl::Util;
require Apache::Response;
}
my $r = Apache->request;
# If bytes have already been sent, then
# we print the message out directly.
# Otherwise we make a custom error
# handler to produce the doc for us.
if ($r->bytes_sent) {
$r->print($mess);
$mod_perl == 2 ? ModPerl::Util::exit(0) : $r->exit;
} else {
print STDOUT $mess;
# MSIE browsers don't show the $mess when sent
# a custom 500 response.
if ($ENV{HTTP_USER_AGENT} =~ /MSIE/) {
$r->send_http_header('text/html');
$r->print($mess);
$r->exit();
} else {
$r->custom_response(500,$mess);
}
}
} else {
print STDOUT $mess;
}
}

# Cut and paste from CGI.pm so that we don't have the overhead of
Expand Down
3 changes: 2 additions & 1 deletion cgi_docs.html
Expand Up @@ -4762,6 +4762,7 @@ <H2><a name="bugs">Bug Reports</a></H2>
<H2><A NAME="new">Revision History</A></H2>
<h3>Version 2.92</h3>
<ol>
<li>Patch from Steve Hay to make CGI::Carp's error messages appear on MSIE browsers.
<li>Added Yair Lenga's patch for non-urlencoded postings.
<li>Added Stas Bekman's patches for mod_perl 2 compatibility.
<li>Fixed uninitialized escape behavior submitted by William Campbell.
Expand Down Expand Up @@ -5802,6 +5803,6 @@ <H3>Bug fixes</H3>
<a href="http://www.cshl.org/">Cold Spring Harbor Laboratory</a></ADDRESS>
<P>
<!-- hhmts start -->
Last modified: Fri Apr 11 10:13:09 EDT 2003
Last modified: Fri Apr 11 16:46:22 EDT 2003
<!-- hhmts end -->
</BODY> </HTML>

0 comments on commit d20f76e

Please sign in to comment.