If multiple handlers are defined for a phase and a handler which isn't the last one, rather than returning the value apache.OK as the result, raises the apache.SERVER_RETURN exception with apache.OK as argument, then processing of subsequent handlers in that phase are being aborted.
Ie., consider the example with .htaccess file of:
and example.py of:
from mod_python import apache
req.content_type = 'text/plain'
- return apache.OK
raise apache.SERVER_RETURN, apache.OK
The expectation would be that returning the value apache.OK from the handler function and raising an exception of type apache.SERVER_RETURN with argument apache.OK would be equivalent, but they aren't. When the exception is being raised, handler_2() function is never executed.
It would seem more sensible that they are equivalent as there are other specific status values that can be used in the case that one wants to prevent further handlers in the phase from being executed. For example, as appropriate, one of:
req.status = apache.HTTP_OK
raise apache.SERVER_RETURN, apache.DONE
raise apache.SERVER_RETURN, (apache.DONE,apache.HTTP_OK)
raise apache.SERVER_RETURN, apache.DECLINED
To fix this, the apache.SERVER_RETURN exception should be processed within the processing loop for each handler, rather than being handled outside of the loop. The status as returned by the exception should be translated to look like it was returned by the handler and dealt with as for other status values returned explicitly.
No patch, perhaps wait for my rewrite of the importer for mod_python 3.3 as already addresses this issue.