]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Test and document the legacy HTTPRequest.write interface.
authorBen Darnell <ben@bendarnell.com>
Sun, 27 Apr 2014 15:36:54 +0000 (11:36 -0400)
committerBen Darnell <ben@bendarnell.com>
Sun, 27 Apr 2014 15:36:54 +0000 (11:36 -0400)
tornado/http1connection.py
tornado/test/httpserver_test.py

index fbe65ebf0a2e3706b266c9757b7be127aa4ecbf8..22485f1460799296b8fbb960a6ecab475ad3a3df 100644 (file)
@@ -345,7 +345,12 @@ class HTTP1Connection(httputil.HTTPConnection):
             return chunk
 
     def write(self, chunk, callback=None):
-        """Implements `.HTTPConnection.write`."""
+        """Implements `.HTTPConnection.write`.
+
+        For backwards compatibility is is allowed but deprecated to
+        skip `write_headers` and instead call `write()` with a
+        pre-encoded header block.
+        """
         if self.stream.closed():
             self._write_future = Future()
             self._write_future.set_exception(iostream.StreamClosedError())
index dc31dc54c96f0ea2c9853353f1dd70873e122b75..f9e920cd9a995ab4d91d3056e9e00889c78567c2 100644 (file)
@@ -1011,3 +1011,21 @@ class BodyLimitsTest(AsyncHTTPTestCase):
             self.assertEqual(data, b'')
         finally:
             stream.close()
+
+
+class LegacyInterfaceTest(AsyncHTTPTestCase):
+    def get_app(self):
+        # The old request_callback interface does not implement the
+        # delegate interface, and writes its response via request.write
+        # instead of request.connection.write_headers.
+        def handle_request(request):
+            message = b"Hello world"
+            request.write(utf8("HTTP/1.1 200 OK\r\n"
+                               "Content-Length: %d\r\n\r\n" % len(message)))
+            request.write(message)
+            request.finish()
+        return handle_request
+
+    def test_legacy_interface(self):
+        response = self.fetch('/')
+        self.assertEqual(response.body, b"Hello world")