]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Don't log errors about content-length mismatch when the connection closes.
authorBen Darnell <ben@bendarnell.com>
Sat, 19 Apr 2014 20:04:53 +0000 (16:04 -0400)
committerBen Darnell <ben@bendarnell.com>
Sat, 19 Apr 2014 20:04:53 +0000 (16:04 -0400)
tornado/http1connection.py
tornado/test/web_test.py

index b64425223e86db2252264c3e0fb92e9175732741..5c50fad000df0512ff49431a28909c575d0941fc 100644 (file)
@@ -298,7 +298,8 @@ class HTTP1Connection(object):
     def finish(self):
         """Finishes the request."""
         if (self._expected_content_remaining is not None and
-            self._expected_content_remaining != 0):
+            self._expected_content_remaining != 0 and
+            not self.stream.closed()):
             self.stream.close()
             raise httputil.HTTPOutputException(
                 "Tried to write %d bytes less than Content-Length" %
index e05ae069702276be223e06b91b9cd48247720b54..92b768f60b5dfef62dbdca04cc6ca8798a24eea6 100644 (file)
@@ -1962,6 +1962,7 @@ class IncorrectContentLengthTest(SimpleHandlerTestCase):
                     self.finish("hello")
                 except Exception as e:
                     test.server_error = e
+                    raise
 
         return [('/high', TooHigh),
                 ('/low', TooLow)]
@@ -1989,3 +1990,19 @@ class IncorrectContentLengthTest(SimpleHandlerTestCase):
         self.assertEqual(response.code, 599)
         self.assertEqual(str(self.server_error),
                          "Tried to write more data than Content-Length")
+
+
+class ClientCloseTest(SimpleHandlerTestCase):
+    class Handler(RequestHandler):
+        def get(self):
+            # Simulate a connection closed by the client during
+            # request processing.  The client will see an error, but the
+            # server should respond gracefully (without logging errors
+            # because we were unable to write out as many bytes as
+            # Content-Length said we would)
+            self.request.connection.stream.close()
+            self.write('hello')
+
+    def test_client_close(self):
+        response = self.fetch('/')
+        self.assertEqual(response.code, 599)