i've been developing in zope for quite a while (not using the management
gui, primarily using DTML, Acquisition, and ZPublisher), and i see webware
having some nice features. One thing I couldn't find in webware was the
ability to do streaming response writes. let me clarify...
Say i have a method that needs to stream a data to the browser...
in zope i would do this:
def somemethod(self, REQUEST):
""" some published method """
REQUEST.response.setHeader('content-type', 'application/octet-stream')
# this is a simple example of write, in the real world, i would open a
file
# (or do a popen) and do a while loop and read chunks off the file and do
a
# write to the browser until the file is complete
REQUEST.response.write('x' * 16384) # write some data to browser
REQUEST.response.write('x' * 16384) # write some more data
in mod_python i would do this (i probably have my function calls screwed up,
but you get the idea):
def handler(req):
req.content_type('application/content-type')
req.send_http_headers()
req.write('x' * 8192) # write some data to browser
req.write('x' * 8192) # write some more data
return apache.OK
i did a test with mod_python and linux netscape where i did writes
interlaced with sleeps. i discovered that if the data i write is big enough
(a hundred characters), it gets immediately written to the browser.
i looked around in the webware/webkit directory, but saw that responses were
being collected and sent back on one shot (the x's would be collected to a
single string in the above examples and chew up memory). if the returned
content is a large amount of data, this poses problems. for most of my
application, collecting response data to a string would be okay, as it
returns simple html. however, we also gzip files (which could potentially
be very large) and stream it the browser, so collecting the data into a huge
python string (or a temporary file) isn't an option. i thought
UnknownFileTypeServlet would have some code to allow writes to be
instantaneously be propogated to the browser, but it doesn't. it seems the
object that needs to support this kind of feature would need to go into
HTTPResponse.
is there already support for streamed writes that i haven't seen. if not,
will it be supported?
|