Hi.
[ I use Apache 1.3.9 and mod_perl 1.21. ]
I believe that there is a difference between the following two
behaviors for an Apache module handler:
-- setting the request's status field to a new value and also
returning that value;
-- just returning a value without assigning it to the
request's status field.
It's an useful thing that a mod_perl script (what
Apache::Registry::handler calls) be able to decide that, e.g.,
HTTP_NOT_FOUND, should be returned to the browser and just return
then.
# example mod_perl script
use Apache::Constants ':response';
my $r = Apache->request;
if (...) {
$r->status(NOT_FOUND);
return;
}
$r->content_type('text/html');
...
We then expect that the normal ErrorDocument, as configured, should be
returned in that case. However, this is not what happens because
Apache::Registry chooses the first behavior listed above and so an
HTTP_NOT_FOUND also seem to affect the ErrorDocument then. The useful
behavior would be the second one listed above.
Ideally, a method such as $r->return_value could be defined,
independently of $r->status, and its argument could then be used when
Apache::Registry::handler returns. An other possibily which can
probably be ruled out for compatibily with CGI scripts and other
reasons is to use the return value from the mod_perl script itself.
I have appended a patch to Apache::Registry below which I believe to
be an acceptable solution for now. (It really disallows a script to
set the status field using the possibly changed status field as return
value.)
Your comments are welcome. Do you think that such a change or what I
mention above ($r->return_value) should make it in the main
distribution of mod_perl?
Charles
========================================================================
--- Registry.pm.orig-1.21 Tue Jan 12 21:56:34 1999
+++ Registry.pm Thu Jan 13 14:50:56 2000
@@ -131,6 +131,8 @@
$Apache::Registry->{$package}{'mtime'} = $mtime;
}
+ my $old_status = $r->status;
+
my $cv = \&{"$package\::handler"};
eval { &{$cv}($r, @_) } if $r->seqno;
$r->chdir_file("$Apache::Server::CWD/");
@@ -155,7 +157,9 @@
# return REDIRECT;
# }
# }
- return $r->status;
+ my $return_value = $r->status;
+ $r->status($old_status);
+ return $return_value;
} else {
return NOT_FOUND unless $Debug && $Debug & 2;
return Apache::Debug::dump($r, NOT_FOUND);
========================================================================