perl-asp mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stas Bekman <>
Subject Re: [mp2] Apache::OK vs 200
Date Sat, 22 Nov 2003 20:10:20 GMT
Perrin Harkins wrote:
> On Sat, 2003-11-22 at 11:55, Randy Kobes wrote:
>>Is there something wrong in principle with returning an
>>explicit status of, eg, 200, rather than using the Apache::*
> As I understand it, they are two different things.  The Apache constants
> are for telling apache what's going on and do not necessarily correspond
> to values in HTTP.

Not so much about the constants (since you can use just numbers), but about 
the values expected to be returned from the handler.

In order to support stacked handlers Apache expects a handler to return one of 
the special Apache::OK, Apache::DECLINED, Apache::DONE or an HTTP_ code (or 
its alias, e.g SERVER_ERROR instead of HTTP_INTERNAL_SERVER_ERROR). The first 
two codes ensure the continuation of the request loop, all the rest abort it.

We used to have special handling of return codes to guess what the user may 
have meant, but recently decided to drop any second guessing and always return 
to Apache whatever the handler has returned. Therefore earlier we were always 
doing status =~ s/200/0/, now we don't.

Handlers should always return one of the above three codes when everything is 
OK, returning any other code is an error to Apache, because it'll break the 
request loop. The internal Apache logic goes as:

   if (status = phase1()) { // e.g. header_parser
      return status;
   if  (status = phase2()) { // e.g. trans
      return status;
   if (status = phaseN()) { // e.g. fixup
      return status;

so only when a handler returns OK or DECLINED will the request loop continue 
(see the URL above). Any other return code will break the flow at the current 
phase and no other phase will be executed (besides logging and cleanup phases 
which always get executed). So for example if you return Apache::DONE at the 
header_parser phase, no other phases will be executed.

And if you return Apache::HTTP_OK, in response handler it's essentially an 
error too. If people feel really strong about it, we can put back the special 
case for Apache::HTTP_OK. Though if you think about it, it makes your life 
much simpler is you remember that all you have to return in OK or DECLINED to 
continue and anything else will abort the normal loop. I hope you will agree 
with me.

Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker     mod_perl Guide --->

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message