1. shishir kumar
  2. CherryPy

Commits

Robert Brewer  committed a61b0ca

Safer wsgi close.

  • Participants
  • Parent commits 1fef7bb
  • Branches default

Comments (0)

Files changed (2)

File cherrypy/_cpwsgiserver.py

View file
     
     def respond(self):
         response = self.wsgi_app(self.environ, self.start_response)
-        for line in response:
-            self.write(line)
-        if hasattr(response, "close"):
-            response.close()
+        try:
+            for line in response:
+                self.write(line)
+        finally:
+            if hasattr(response, "close"):
+                response.close()
         if (self.ready and not self.sent_headers
                 and not self.connection.server.interrupt):
             self.sent_headers = True

File cherrypy/lib/wsgiapp.py

View file
         environ.update(env)
     
     # run the wsgi app and have it set response.body
-    cherrypy.response.body = app(environ, start_response)
+    response = app(environ, start_response)
+    try:
+        cherrypy.response.body = response
+    finally:
+        if hasattr(response, "close"):
+            response.close()
     
     return True