From: Ben Darnell Date: Sun, 27 Apr 2014 15:36:54 +0000 (-0400) Subject: Test and document the legacy HTTPRequest.write interface. X-Git-Tag: v4.0.0b1~91^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8630b3b7ede744fc3824b36dc1bbfcfb021155f9;p=thirdparty%2Ftornado.git Test and document the legacy HTTPRequest.write interface. --- diff --git a/tornado/http1connection.py b/tornado/http1connection.py index fbe65ebf0..22485f146 100644 --- a/tornado/http1connection.py +++ b/tornado/http1connection.py @@ -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()) diff --git a/tornado/test/httpserver_test.py b/tornado/test/httpserver_test.py index dc31dc54c..f9e920cd9 100644 --- a/tornado/test/httpserver_test.py +++ b/tornado/test/httpserver_test.py @@ -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")