summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2012-12-30 15:08:06 +0100
committerAymeric Augustin <aymeric.augustin@m4x.org>2012-12-31 12:48:43 +0100
commitac72782e61a8e08381cb66005295a4c24ed37f33 (patch)
tree27f3f8746a0431fd3002fb0db0301dfefb068db0
parent814c3b2e2a8da001af38f679ed2334239150a975 (diff)
[1.5.x] Fixed #16241 -- Ensured the WSGI iterable's close() is always called.
Thanks Graham Dumpleton for the report. Backport of a53c474.
-rw-r--r--django/core/servers/basehttp.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/django/core/servers/basehttp.py b/django/core/servers/basehttp.py
index 7387d13199..68ca0c1079 100644
--- a/django/core/servers/basehttp.py
+++ b/django/core/servers/basehttp.py
@@ -109,6 +109,17 @@ class ServerHandler(simple_server.ServerHandler, object):
super(ServerHandler, self).error_output(environ, start_response)
return ['\n'.join(traceback.format_exception(*sys.exc_info()))]
+ # Backport of http://hg.python.org/cpython/rev/d5af1b235dab. See #16241.
+ # This can be removed when support for Python <= 2.7.3 is deprecated.
+ def finish_response(self):
+ try:
+ if not self.result_is_file() or not self.sendfile():
+ for data in self.result:
+ self.write(data)
+ self.finish_content()
+ finally:
+ self.close()
+
class WSGIServer(simple_server.WSGIServer, object):
"""BaseHTTPServer that implements the Python WSGI protocol"""