Skip to content

Commit

Permalink
Fixed issue with (multiple) BOM's in response.
Browse files Browse the repository at this point in the history
  • Loading branch information
berry committed Aug 4, 2010
1 parent ab9818a commit a546df7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README
Expand Up @@ -9,7 +9,7 @@ The code currently handles a couple of simple WSGI application. It also handles


Known issues: Known issues:
- this wsgi handler currently doesn't support chunked responses. I haven't figured out yet how to do this. - 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 issues:
- [FIXED 4 aug 2010] the handler does not handle query strings correctly right now. Still have to fix and test this. - [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.
1 change: 1 addition & 0 deletions test_wsgi_app.py
Expand Up @@ -33,6 +33,7 @@
__file__ = '?' __file__ = '?'


html_template = u"""\ html_template = u"""\
<!DOCTYPE html>
<html> <html>
<head> <head>
<title>WSGI Test Script</title> <title>WSGI Test Script</title>
Expand Down
9 changes: 8 additions & 1 deletion wsgi-handler.py
Expand Up @@ -43,7 +43,7 @@ def wsgi_server(application):
A WSGI application should return a iterable op StringTypes. A WSGI application should return a iterable op StringTypes.
Any encoding must be handled by the WSGI application itself. Any encoding must be handled by the WSGI application itself.
''' '''

while True: while True:
if DEBUG: print "WAITING FOR REQUEST" if DEBUG: print "WAITING FOR REQUEST"


Expand Down Expand Up @@ -93,6 +93,13 @@ def wsgi_server(application):
code = response[0][9:12] code = response[0][9:12]
status = response[0][13:] 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 # Get the generated errors
errors = errIO.getvalue() errors = errIO.getvalue()


Expand Down

0 comments on commit a546df7

Please sign in to comment.