[mod_python] Serving FS data

Graham Dumpleton grahamd at dscpl.com.au
Tue Jan 18 16:45:48 EST 2005

If you are using "SetHandler" to intercept all requests falling
below a directory and the raw files you want to send back are
under this directory with the correct location corresponding to
the request already, there are a couple of other things that
may also be appropriate.

First off, you can simply put:

   return apache.DECLINED

in your handler for any specific request you aren't doing anything
special for.

Doing this, control gets passed back to Apache and it will use
the standard mechanisms for returning the contents of any file
it finds at the location identified by the URL.

Second is that if all the files that need to be sent back use the
same extension, you can avoid triggering off mod_python in the
first place, by having in your httpd.conf/htaccess file something

   SetHandler mymodule

   <Files *.jpg>
   SetHandler None

This one is also useful where you are also using PHP.

   SetHandler mymodule

   <Files *.php>
   SetHandler None

Doing this, you can mix PHP and mod_python stuff in the one directory
which can be handy if wanting to slowly migrate stuff from PHP to
mod_python. :-)


On Wednesday, January 19, 2005, at 02:46  AM, Nicolas Lehuen wrote:

> Use req.sendfile(). See :
> http://www.modpython.org/pipermail/mod_python/2005-January/017118.html
> Maybe we should add this to the FAQ 
> (http://www.modpython.org/FAQ/faqw.py) ?
> Regards,
> Nicolas
> On Tue, 18 Jan 2005 16:21:04 +0100, Igor Stroh <igor at rulim.de> wrote:
>> Hi there,
>> I'm looking for a way to serve files from the filesystem
>> through mod_python. Right now I'm just doing stuff like
>> request.write(file(<path>).read())
>> but this is obviously quite expensive when the files are
>> big, since they're dumped at once into memory...
>> The whole thing would be ways faster if there would be
>> a way to just "pipe" those files through mod_python
>> directly to apache, i.e. just by pointing to a path
>> or a file descriptor... Any ideas?
>> TIA,
>> Igor
>> _______________________________________________
>> Mod_python mailing list
>> Mod_python at modpython.org
>> http://mailman.modpython.org/mailman/listinfo/mod_python
> _______________________________________________
> 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