[mod_python] PostReadRequestHandler

Jim Hefferon jim at joshua.smcvt.edu
Fri Jul 15 15:50:09 EDT 2005


Hello,  

I'm sorry to bother folks, but I have a "Hello World"-type question.  

I want to write a small handler that redirects if the URI satisfies some
criteria (I have pre-made some autoindex pages and so want to redirect
to those if possible).  My understanding of handlers is very weak, but I
thought that a PostReadRequestHandler is the right thing, as then all
the URI translations, etc. can do their stuff after I reroute some
URI's.  That is, I had in mind something like his:
  def postreadrequesthandler(req):
     uriPath=req.parsed_uri[apache.URI_PATH]
     if uriPath satisfies criteria:
        redirect
        return apache.OK
     return apache.DECLINED

I put these lines in my 000-default in a virtual host context:
  setHandler mod_python
  PythonPath "sys.path+['/dir/containing/py/file']"
  PythonPostReadRequestHandler filename
  PythonDebug On
The error.log says something about mod_python 3.1.3 resuming normal
operations, so I think I am OK.

I wrote a small handler, just as a test.  It says only
  def postreadrequesthandler(req):
    return apache.DECLINED
(I've also experimented with apache.OK)  I expected it to have no effect
on the behavior of apache as my understanding was that the request would
go to the next handler up the line.

Instead, when I restart apache, it gives me a 404 every time, and every
time sends me a copy of the cgi program that is the 404 error handler. 
That is, that the 404 should be executed as a cgi is gone (of course, it
works if I comment out the lines above from the 000-default and restart
and ask for something that isn't there).  The error.log says "attempt to
serve directory" so it is not looking for the index.html file in the
dir.  So I'm thinking that all subsequent handlers are not being
invoked, or else that I am just clueless (I suspect that latter!).

I have the latest Debian, am using Apache 2.0, and got mod_python
pre-packaged (that is, I didn't compile it myself, or anything). 

No doubt I'm doing something dopey, but I usually write by starting with
a small script that works and expanding.  I'm unable to get the small
script to go here.  If someone has a suggestion, I'd be very grateful.

Thanks,
Jim Hefferon

-- 
If there’s one thing we’ve learned, it’s that there is no such thing as
cheap meta-data.  --Tim Bray



More information about the Mod_python mailing list