[mod_python] Chaining handlers

David Champion dgc at uchicago.edu
Wed Mar 19 16:14:19 EDT 2008

This seems like it should be a FAQ, but I don't see it.  Sorry if I've
missed it -- pointers instead of answers are welcome.

I thought I understood that it's possible to chain handlers in Apache,
such that multiple handlers can have a chance at completing the request,
and the chain ends when a handler succeeds.  (I don't want to "pipeline"
filters, so that each handler handles the same request in succession.)
But I'm having trouble seeing how to make this work.

More specifically, what I'm trying to accomplish is to have mod_python
implement an access control policy over a directory.  Provided that
access is allowed, I want any content in that directory to be served as
if mod_python were not present.  I have a script that implements the
policy.  It amounts to this:

	<Location /test/*>
		SetHandler mod_python
		PythonHandler MyPackage

	def handler(req):
		# case 1
		if accessOK(req):
			return apache.DECLINED

		# case 2
			return apache.UNAUTHORIZED

Case 2 works, of course.  And when I request a static file, case 1 works
too (I receive the file).  My problem is when the request is for an
object that's covered by some other handler -- cgi, php, etc.  I receive
the CGI as a static-content test/plain file instead.

Is this possible?  I feel like I must be missing something; there's a
lot I still don't understand about the API.  I had started to implement
this module in C, but decided I could probably do it in mod_python if
it's possible in C.  Is that true?

 -D.    dgc at uchicago.edu    NSIT    University of Chicago

More information about the Mod_python mailing list