Graham Dumpleton
graham.dumpleton at gmail.com
Sat Jun 9 02:02:07 EDT 2007
On 09/06/07, Aaron Gallagher <habnabit at gmail.com> wrote: > > Is there any easy way to make req.sendfile use a content-length header > instead of chunking the output? This is what I've been doing, and it's very > fast, but I'm sure there's a more elegant way of doing it. > > st = open(req.filename) > st.seek(0, 2) > req.set_content_length(st.tell()) > st.close() > req.sendfile(req.filename) What you are doing isn't actually guaranteed to yield the correct result as the file might be changed between the close() and the call to sendfile() and thus you could end up sending a different amount of data. Note that if your mod_python handler simply returns apache.DECLINED, the file defined by req.filename will be served up as static file for you by Apache. If you are instead using mod_python.publisher, use: raise apache.SERVER_RETURN, apache.DECLINED Let us know if this works as I expect it should. If you have changed req.filename there are some further steps you will need to possibly do to have it work like I expect. Graham
|