[mod_python] Chaining handlers

Graham Dumpleton graham.dumpleton at gmail.com
Mon Mar 24 16:19:07 EDT 2008


On 25/03/2008, David Champion <dgc at uchicago.edu> wrote:
> > Don't define SetHandler here. This says that mod_python is handling
>  > the content phase which you don't want as you want your CGI script to
>  > do that.
>  >
>  > Ie., only define SetHandler or AddHandler as appropriate when using
>  > PythonHandler directive.
>
> OK, sorry for a basic Apache question, but how do I "add" a handler
>  without specifying what content type/extension it's going to handle
>  content for?

For the content handler phase, ie., PythonHandler, you can't. That is,
you cannot chain mod_python and non mod_python handlers within the
content handler phase. The only half exception to this is if
mod_python content handler returns DECLINED then control will still
pass through to 'default-handler' which serves up target as static
file.

>  My module should be asked to handle every file under the <Location>,
>  regardless of extension or content type.  It will decide whether to
>  decline according to its own principles, not according to type.

Register a fixup handler and put PythonFixupHandler in that Location
container. If you then want to hijack content handling phase for that
request and override what else was meant to happen, from memory do the
following in fixup handler and return:

  req.handler = 'mod_python'
  req.add_handler('PythonHandler', somehandlerfunc)

Check documentation for the mod_python request add_handler() function
as probably haven't remembered the arguments correctly.

Do note that mod_python handlers get added as middle handlers and you
can't control their position relative to handlers in same phase. This
may be limiting for example if you actually had to ensure it was run
after mod_dir handler in fixup phase. You may therefore need to do
extra checks to avoid doing stuff which you shouldn't because later
handler in that phase may want to do it. Eg. trailing slash
redirection.

Graham

>  I couldn't find any way to do this with mod_python.  With my C module,
>  it's not necessary -- I just put its custom configuration directives
>  within the <Location> block.  But mod_python has no analogous behavior
>  that I can see, and I can't tell how to say "use mod_python with these
>  params" without setting a handler.
>
>
>  --
>
>  -D.    dgc at uchicago.edu    NSIT    University of Chicago
>
> _______________________________________________
>  Mod_python mailing list
>  Mod_python at modpython.org
>  http://mailman.modpython.org/mailman/listinfo/mod_python
>


More information about the Mod_python mailing list