[mod_python] setting content_type intelligently

Michael C. Neel neel at mediapulse.com
Thu Feb 5 10:47:08 EST 2004


> <Location ...> directives live in url space, completely outside from
> the filesystem.  I have my app configured like this:
> 
> 
>     <Location /site>
>     SetHandler python-program
>     PythonHandler ...
>     ...
>     </Location>
> 
> When requests come in, such as http://myserver/site/foo/bar, my
> handler will use 'foo/bar' to determine what it sends back to the
> client and, generally, use the pathinfo as a relative path from a data
> directory configured, purposefully, outside of DocumentRoot.  So, how
> do I set content-type correctly for content I don't generate, ie,
> images?
> 
> If my app was <Directory> based, I could raise apache.SERVER_RETURN
> with apache.DECLINED; apache would have means to find the file and "do
> the right thing," but inside <Location> there is NO filesystem, thus
> my 404 error.
> 

You can still return apache.DECLINED from Location's, I do this all the
time for files I don't want to handle.  Since your location doesn't
exist under document root, make sure the items you are declining do.
Something like:

/safe_dir/foo/bar/pages.html
/docroot/foo/bar/images.gif

However, a better solution imho would be to not reference images in the
/site url, i.e. images are all in /images under doc root and therefore
the location /site would never get called.

hth,
Mike



More information about the Mod_python mailing list