From 9f572bc8ead64d8f9896ceb25d2a3d3eac770421 Mon Sep 17 00:00:00 2001 From: benoitc Date: Sun, 21 Mar 2010 10:30:57 +0100 Subject: [PATCH] add headers_sent guard. --- gunicorn/http/request.py | 3 ++- gunicorn/http/response.py | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/gunicorn/http/request.py b/gunicorn/http/request.py index 00a8d609..3bdfbb10 100644 --- a/gunicorn/http/request.py +++ b/gunicorn/http/request.py @@ -54,6 +54,7 @@ class Request(object): self.start_response_called = False self.log = logging.getLogger(__name__) self.response_chunked = False + self.headers_sent = False def read(self): environ = {} @@ -156,7 +157,7 @@ class Request(object): def start_response(self, status, response_headers, exc_info=None): if exc_info: try: - if self.start_response_called: + if self.headers_sent: raise exc_info[0], exc_info[1], exc_info[2] finally: exc_info = None diff --git a/gunicorn/http/response.py b/gunicorn/http/response.py index 46551672..551b4bfa 100644 --- a/gunicorn/http/response.py +++ b/gunicorn/http/response.py @@ -29,6 +29,8 @@ class Response(object): resp_head = self.default_headers() resp_head.extend(["%s: %s\r\n" % (n, v) for n, v in self.headers]) write(self._sock, "%s\r\n" % "".join(resp_head)) + self.req.headers_sent = True + last_chunk = None for chunk in self.data: