From 8b693dacf8777548af3cc6f6613ca39d7f3c137c Mon Sep 17 00:00:00 2001 From: ianb Date: Tue, 20 Mar 2007 00:13:08 +0000 Subject: Give a better error when start_response isn't called; give a Content-Length so that the connection is closed properly on error --- paste/httpserver.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'paste/httpserver.py') diff --git a/paste/httpserver.py b/paste/httpserver.py index d2d0c16..8f70cc4 100755 --- a/paste/httpserver.py +++ b/paste/httpserver.py @@ -120,6 +120,9 @@ class WSGIHandlerMixin: Write a chunk of the output stream; send headers if they have not already been sent. """ + if not self.wsgi_headers_sent and not self.wsgi_curr_headers: + raise RuntimeError( + "Content returned before start_response called") if not self.wsgi_headers_sent: self.wsgi_headers_sent = True (status, headers) = self.wsgi_curr_headers @@ -284,8 +287,11 @@ class WSGIHandlerMixin: return except: if not self.wsgi_headers_sent: - self.wsgi_curr_headers = ('500 Internal Server Error', - [('Content-type', 'text/plain')]) + error_msg = "Internal Server Error\n" + self.wsgi_curr_headers = ( + '500 Internal Server Error', + [('Content-type', 'text/plain'), + ('Content-length', str(len(error_msg)))]) self.wsgi_write_chunk("Internal Server Error\n") raise -- cgit v1.2.1