[Web-SIG] Emulating req.write() in WSGI

Aaron Fransen aaron.fransen at gmail.com
Wed Jul 7 15:20:33 CEST 2010


Well, just in case this helps anyone, I managed to get it working on most of
the current browsers.

My first problem was a missing import statement (definite "DOH!" moment
there), but once that was resolved Firefox steadfastly refused to
co-operate.

The fix was to use a boundary indicator then specify the content type for
every subsequent chunk of data, something along these lines:

# during initial converstation
     status    = '200 OK'
     response_headers  = [('Content-type','multipart/x-mixed-replace')]
     if string.find(environ['HTTP_USER_AGENT'],'Firefox') != -1:
         response_headers  =
[('Content-type','multipart/x-mixed-replace;boundary=x0x0x0x')]
     writer = start_response(status, response_headers)

# during subsequent conversations
    if string.find(environ['HTTP_USER_AGENT'],'Firefox') != -1:
        writer('Content-type: text/html\r\n\r\n'+text+'\r\n\r\n--x0x0x0x')
    else:
        writer(text)

Now, in Firefox the behavior is that it completely replaces the previous
chunk, while in IE8, Chrome, Safari it simply adds to the existing content.
It doesn't work in Opera yet (with either method), I haven't been able to
determine why but I'll continue to work on it.

Sorry for the hassle everyone!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/web-sig/attachments/20100707/bf6f6849/attachment.html>


More information about the Web-SIG mailing list