add headers_sent guard.

This commit is contained in:
benoitc 2010-03-21 10:30:57 +01:00
parent 125392d054
commit 9f572bc8ea
2 changed files with 4 additions and 1 deletions

View File

@ -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

View File

@ -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: