[mod_python] [Patch] req.write_file for 3.0.x

Conrad Steenberg conrad at hep.caltech.edu
Tue May 6 01:49:51 EST 2003


Ugh, pressed the send button before finishing the code snippet:

def handler(req):
  req.content_type='text/html'
  req.send_http_header()
  sent=0
  while sent>=0:
    sent = req.write_file("/var/www/html/index.html",0,-1)
  return apache.OK

Conrad

On Tue, 2003-05-06 at 01:36, Conrad Steenberg wrote:
> Hi
> 
> Attached is a patch (against 3.0.1 but probably works for all 3.0.x) for
> src/requestobject.c to allow mod_python programs to send files
> efficiently using the available Apache machinery for both unencrypted
> and SSL/TLS connections.
> 
> What does it do?
> ----------------
> 
> Implements a file_write() method for the Request object. It does NOT
> write headers, only the file.
> 
> E.g.
> 
> def handler(req):
>   req.content_type='text/html'
>   req.send_http_header()
>   sent=0
>   while 
>   req.write_file("/var/www/html/index.html",0,-1)
>   return apache.OK
> 
> The first argument is the filename, the second is the offset to start
> reading in the file, the third argument is the number of bytes to write.
> The last two arguments are optional.
> 
> The return value is the number of bytes written, which may be less than
> the total number of bytes in the file. See the manpage of sendfile for
> more details.
> 
> The patch is NOT OS- or architecture dependent, it merely lets Apache
> call its output handler, in the same way that req.write() does for
> string data.
> 
> If there is interest, the patch can developed further to also set the
> content-type, send headers and iterate until the whole file is sent.
> 
> Cheers
> 
> Conrad
-- 
Conrad Steenberg <conrad at hep.caltech.edu>


More information about the Mod_python mailing list