Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed issue with (multiple) BOM's in response.

  • Loading branch information...
commit a546df7985a201ce7daf73cda34ae8c28948b109 1 parent ab9818a
@berry berry authored
Showing with 10 additions and 2 deletions.
  1. +1 −1  README
  2. +1 −0  test_wsgi_app.py
  3. +8 −1 wsgi-handler.py
View
2  README
@@ -9,7 +9,7 @@ The code currently handles a couple of simple WSGI application. It also handles
Known issues:
- this wsgi handler currently doesn't support chunked responses. I haven't figured out yet how to do this.
-- Using the Django demo app I get some strange HTML parsing errors in Chrome. It says "Extra <html> encountered...". Which leads to a couple a follow up parsing errors. It apparently has something to do with unicode and a BOM being present in the response data. Strange.
Fixed issues:
- [FIXED 4 aug 2010] the handler does not handle query strings correctly right now. Still have to fix and test this.
+- [UGLY FIX 4 aug 2010 - Removing BOM(s) before returning the response] Using the Django demo app I get some strange HTML parsing errors in Chrome. It says "Extra <html> encountered...". Which leads to a couple a follow up parsing errors. It apparently has something to do with unicode and a BOM being present in the response data. Strange. Hmmm, the Django development server (./manage runserver) has the same problem.
View
1  test_wsgi_app.py
@@ -33,6 +33,7 @@
__file__ = '?'
html_template = u"""\
+<!DOCTYPE html>
<html>
<head>
<title>WSGI Test Script</title>
View
9 wsgi-handler.py
@@ -43,7 +43,7 @@ def wsgi_server(application):
A WSGI application should return a iterable op StringTypes.
Any encoding must be handled by the WSGI application itself.
'''
-
+
while True:
if DEBUG: print "WAITING FOR REQUEST"
@@ -93,6 +93,13 @@ def wsgi_server(application):
code = response[0][9:12]
status = response[0][13:]
+ # strip BOM's from response data
+ # Especially the WSGI handler from Django seems to generate them (2 actually, huh?)
+ # a BOM isn't really necessary and cause HTML parsing errors in Chrome and Safari
+ # See also: http://www.xs4all.nl/~mechiel/projects/bomstrip/
+ # Although I still find this a ugly hack.
+ data = data.replace('\xef\xbb\xbf', '')
+
# Get the generated errors
errors = errIO.getvalue()
Please sign in to comment.
Something went wrong with that request. Please try again.