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" %
self.finish("hello")
except Exception as e:
test.server_error = e
+ raise
return [('/high', TooHigh),
('/low', TooLow)]
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)