From 95e93f0660b42e2a947e58d1f3a18159febeb660 Mon Sep 17 00:00:00 2001 From: donovan Date: Mon, 5 Jan 2009 18:47:00 -0800 Subject: [PATCH] When a wsgi application gives a unicode object to the server, which the spec says causes undefined behavior, write a 500 error to the browser instead of just hanging forever. --- eventlet/wsgi.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/eventlet/wsgi.py b/eventlet/wsgi.py index ca5458d..0613fc9 100644 --- a/eventlet/wsgi.py +++ b/eventlet/wsgi.py @@ -181,7 +181,10 @@ class HttpProtocol(BaseHTTPServer.BaseHTTPRequestHandler): towrite.append(data) joined = ''.join(towrite) length[0] = length[0] + len(joined) - _write(joined) + try: + _write(joined) + except UnicodeEncodeError: + _write("HTTP/1.0 500 Internal Server Error\r\nConnection: close\r\nContent-type: text/plain\r\nContent-length: 98\r\n\r\nInternal Server Error: wsgi application passed a unicode object to the server instead of a string.") def start_response(status, response_headers, exc_info=None): status_code[0] = status.split()[0]