diff --git a/examples/pylonstest/development.ini b/examples/pylonstest/development.ini index 0c17f0f1..92697151 100644 --- a/examples/pylonstest/development.ini +++ b/examples/pylonstest/development.ini @@ -4,7 +4,7 @@ # The %(here)s variable will be replaced with the parent directory of this file # [DEFAULT] -debug = false +debug = true # Uncomment and replace with the address which should receive any error reports #email_to = you@yourdomain.com smtp_server = localhost diff --git a/gunicorn/http/response.py b/gunicorn/http/response.py index f2c7fbe1..001b05f8 100644 --- a/gunicorn/http/response.py +++ b/gunicorn/http/response.py @@ -18,7 +18,7 @@ class HttpResponse(object): def send(self): # send headers resp_head = [] - resp_head.append("HTTP/1.1 %s\r\n" % (self.status)) + resp_head.append("HTTP/1.0 %s\r\n" % (self.status)) resp_head.append("Server: %s\r\n" % self.SERVER_VERSION) resp_head.append("Date: %s\r\n" % http_date()) diff --git a/gunicorn/util.py b/gunicorn/util.py index 47edf765..147b9a19 100644 --- a/gunicorn/util.py +++ b/gunicorn/util.py @@ -61,7 +61,10 @@ def write(sock, data): raise i += 1 - +def writelines(sock, lines): + for line in list(lines): + write(sock, line) + def normalize_name(name): return "-".join([w.lower().capitalize() for w in name.split("-")]) diff --git a/gunicorn/worker.py b/gunicorn/worker.py index f91de8f5..e6d9874a 100644 --- a/gunicorn/worker.py +++ b/gunicorn/worker.py @@ -12,6 +12,7 @@ import signal import socket import sys import tempfile +import traceback from gunicorn import http from gunicorn import util @@ -115,7 +116,19 @@ class Worker(object): util.close_on_exec(client) try: req = http.HttpRequest(client, addr, self.address) - response = self.app(req.read(), req.start_response) + try: + response = self.app(req.read(), req.start_response) + except Exception, e: + exc = ''.join(traceback.format_exception(*sys.exc_info())) + msg = "
%s" % exc + util.writelines(client, + ["HTTP/1.0 500 Internal Server Error\r\n", + "Connection: close\r\n", + "Content-type: text/html\r\n", + "Content-length: %s\r\n" % str(len(msg)), + "\r\n", + msg]) + return http.HttpResponse(client, response, req).send() except Exception, e: self.log.exception("Error processing request. [%s]" % str(e))