[mod_python] Request sendfile question

Mike Looijmans nlv11281 at natlab.research.philips.com
Mon Mar 27 00:52:26 EST 2006


I think the book is getting old - gzip decompression is built into IE 
and Netscape in versions around 4.0, so you can expect them all to 
support it. You can examine the 'accept' header sent by the browser to 
determine whether it will be capable of handling gzipped content.

--
Mike Looijmans
Philips Natlab / Topic Automation


Ville Silventoinen wrote:
> Hi Mike,
> 
> do all browsers support Gzip data? I've got a book called "Writing 
> Apache Modules with Perl and C" which states that only Unix browsers 
> would decompress Gzip data on-the-fly. We've got lot of Windows and Mac 
> users who wouldn't know how to open the .gz file. I know it wastes 
> network bandwidth to send the files uncompressed, but this application 
> is used mostly in our intranet.
> 
> Thanks for you advice,
> 
> Ville
> 
> 
> On Fri, 24 Mar 2006, Mike Looijmans wrote:
> 
>> There is shutil.copyfileobj() which basically does what you do here.
>>
>> If there's only one file in each archive file, your might want to try 
>> just setting the transfer-encoding (or so, not entirely sure here) to 
>> gzipped, just like mod_gzip does (the difference being that mod_gzip 
>> compresses your output, while your output is already compressed). If 
>> you do that right, you can send back the GZIP data without 
>> decompressing it and the client will decompress it on the fly (saving 
>> bandwidth in the process).
>>
>> -- 
>> Mike Looijmans
>> Philips Natlab / Topic Automation
>>
>>
>> Ville Silventoinen wrote:
>>
>>> Hi,
>>>
>>> is there a way to send a file using a file handle?
>>>
>>> I've got a file archive, which stores files in gzip format. When a 
>>> client downloads the file, I'd like to send the file uncompressed, 
>>> without creating a temporary file.
>>>
>>> I'm sending the file like this (bit simplified):
>>>
>>>     req.filename = fname
>>>     req.content_type = ctype
>>>     req.set_content_length = flen
>>>
>>>     fh = gzip.GzipFile(fpath, 'rb', 9)
>>>     block_size = 1024
>>>     while 1:
>>>         data = fh.read(block_size)
>>>         if not data:
>>>             break
>>>         req.write(data)
>>>     fh.close()
>>>
>>>     return apache.OK
>>>
>>> I've tested this with different files, it seems to work ok. I was 
>>> looking at the requestobject.c. Would it be easy to implement 
>>> something like req_sendfh in addition to req_sendfile?
>>>
>>> Thanks,
>>> Ville
>>>
>>> _______________________________________________
>>> 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