[prev in list] [next in list] [prev in thread] [next in thread] 

List:       python-web-sig
Subject:    Re: [Web-SIG] Emulating req.write() in WSGI
From:       Aaron Fransen <aaron.fransen () gmail ! com>
Date:       2010-07-07 13:20:33
Message-ID: AANLkTil-U8Lv0IPJmlJIng19nj7-epd3HI0LBNQKlIPH () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


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!

[Attachment #5 (text/html)]

Well, just in case this helps anyone, I managed to get it working on most of the \
current browsers.<br><br>My first problem was a missing import statement (definite \
&quot;DOH!&quot; moment there), but once that was resolved Firefox steadfastly \
refused to co-operate.<br> <br>The fix was to use a boundary indicator then specify \
the content type for every subsequent chunk of data, something along these \
lines:<br><br># during initial converstation<br>     status    = &#39;200 OK&#39;<br> \
response_headers  = [(&#39;Content-type&#39;,&#39;multipart/x-mixed-replace&#39;)]<br>
  if string.find(environ[&#39;HTTP_USER_AGENT&#39;],&#39;Firefox&#39;) != -1:<br>     \
response_headers  = [(&#39;Content-type&#39;,&#39;multipart/x-mixed-replace;boundary=x0x0x0x&#39;)]<br> \
writer = start_response(status, response_headers)<br> <br># during subsequent \
conversations<br>    if \
string.find(environ[&#39;HTTP_USER_AGENT&#39;],&#39;Firefox&#39;) != -1:<br>        \
writer(&#39;Content-type: \
text/html\r\n\r\n&#39;+text+&#39;\r\n\r\n--x0x0x0x&#39;)<br>    else:<br>  \
writer(text)<br><br>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&#39;t work in Opera yet (with either method), I haven&#39;t been able to \
determine why but I&#39;ll continue to work on it.<br> <br>Sorry for the hassle \
everyone!<br>



_______________________________________________
Web-SIG mailing list
Web-SIG@python.org
Web SIG: http://www.python.org/sigs/web-sig
Unsubscribe: http://mail.python.org/mailman/options/web-sig/python-web-sig%40marc.info


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic