Repository: tornadoweb/tornado

Issue:
http1connection: Send `Connection: close` before closing connection
From https://github.com/tornadoweb/tornado/pull/1963#issuecomment-305983002

When the client sends `Connection: close`, Tornado (correctly) responds by closing the connection after sending the response. [RFC 7230 section 6.6](https://tools.ietf.org/html/rfc7230#section-6.6) says that a server SHOULD set the `Connection: close` header in the response when it does so. 

Discussion:
ploxiln: just one test failure on Python 2.7.8:

```
FAIL: test_connection_refused (tornado.test.iostream_test.TestIOStream)
...
tornado/test/iostream_test.py", line 240, in test_connection_refused
    self.assertFalse(self.connect_called)
AssertionError: True is not false
```

Patch:
diff --git a/tornado/http1connection.py b/tornado/http1connection.py
index c6d3e336..b7a62b8c 100644
--- a/tornado/http1connection.py
+++ b/tornado/http1connection.py
@@ -357,6 +357,10 @@ class HTTP1Connection(httputil.HTTPConnection):
                 # Applications are discouraged from touching Transfer-Encoding,
                 # but if they do, leave it alone.
                 'Transfer-Encoding' not in headers)
+            # If connection to a 1.1 client will be closed, inform client
+            if (self._request_start_line.version == 'HTTP/1.1' and
+                self._disconnect_on_finish):
+                headers['Connection'] = 'close'
             # If a 1.0 client asked for keep-alive, add the header.
             if (self._request_start_line.version == 'HTTP/1.0' and
                 (self._request_headers.get('Connection', '').lower() ==
@@ -418,7 +422,7 @@ class HTTP1Connection(httputil.HTTPConnection):
     def write(self, chunk, callback=None):
         """Implements `.HTTPConnection.write`.
 
-        For backwards compatibility is is allowed but deprecated to
+        For backwards compatibility it is allowed but deprecated to
         skip `write_headers` and instead call `write()` with a
         pre-encoded header block.
         """
diff --git a/tornado/httpserver.py b/tornado/httpserver.py
index 7a7d08cd..95273a36 100644
--- a/tornado/httpserver.py
+++ b/tornado/httpserver.py
@@ -154,7 +154,6 @@ class HTTPServer(TCPServer, Configurable,
                    max_body_size=None, max_buffer_size=None,
                    trusted_downstream=None):
         self.request_callback = request_callback
-        self.no_keep_alive = no_keep_alive
         self.xheaders = xheaders
         self.protocol = protocol
         self.conn_params = HTTP1ConnectionParameters(


Test patch:
diff --git a/tornado/test/httpserver_test.py b/tornado/test/httpserver_test.py
index f5f91a9d..d8342f74 100644
--- a/tornado/test/httpserver_test.py
+++ b/tornado/test/httpserver_test.py
@@ -719,6 +719,7 @@ class KeepAliveTest(AsyncHTTPTestCase):
         self.stream.read_until_close(callback=self.stop)
         data = self.wait()
         self.assertTrue(not data)
+        self.assertEqual(self.headers['Connection'], 'close')
         self.close()
 
     # keepalive is supported for http 1.0 too, but it's opt-in