> I'm trying to handle an exception using an internal_redirect.  I
> can get it to work by redirecting to a static page, but when I try to
> redirect to a modperl handler, I'm run into problems.
>
> Here are the two versions of code (BTW, the handler works fine when I
> access it directly via the browser).
>
> ## ver. 1
> print STDERR "$@";
> require Apache;
> my $r = Apache->request;
> $r->internal_redirect("/DBConnectError.cgi");
>
> ## ver. 2
> print STDERR "$@";
> require Apache;
> my $r = Apache->request;
> $r->internal_redirect("/errordocs/503.html");
>
> When I run the modperl handler, the browser prompts me and asks if I
> want to save the output of the cgi script that raised the error, but
> it never displays the content from the handler. The static file
> version works great and the browser displays it's content.

Hmm... First of all, the Guide (and experience :-) sez that IMMEDIATELY
after running

$r->internal_redirect(blah);

one should

return OK;

Secondly, I would suggest doing it differently:
tell the request object that the handler returned code 503, and in
httpd.conf:

ErrorDocument 503 /DBConnectError.cgi

I just wrote this handler in 2 minutes, that demonstrates:

=========
package Stat::Testfail;

use strict;

sub handler {
    my $r = shift;

    $r->status(503);
    return 503;
}

1;
=========

with the following httpd.conf entry:
<Location /testonly>
SetHandler perl-script
PerlHandler +Stat::Testfail
</Location>

and it works like I've described:

# telnet localhost 80
GET /testonly HTTP/1.0

HTTP/1.1 503 Service Temporarily Unavailable
Date: Tue, 03 Apr 2001 18:01:28 GMT
Server: Apache/1.3.9 (Unix)  (Red Hat/Linux) mod_perl/1.25
Connection: close
Content-Type: text/html

<HTML>
<HEAD><TITLE>An Error Occurred</TITLE></HEAD>
<BODY>
<H1>An Error Occurred</h1>
503 Service Temporarily Unavailable
</BODY>
</HTML>

(Naturally this would have been different if i'd set an ErrorDocument 503).

HTH!

L8r,
Rob

Reply via email to