From: Ben Darnell Date: Sat, 21 Apr 2018 21:01:32 +0000 (-0400) Subject: httputil: Deprecate old interfaces X-Git-Tag: v5.1.0b1~24^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F2360%2Fhead;p=thirdparty%2Ftornado.git httputil: Deprecate old interfaces This is mainly preparation for HTTP/2: request.write was designed to mix headers and bodies in a way that is no longer supported. --- diff --git a/tornado/httputil.py b/tornado/httputil.py index 3d2d3359d..9c607b8c8 100644 --- a/tornado/httputil.py +++ b/tornado/httputil.py @@ -29,6 +29,7 @@ import email.utils import numbers import re import time +import warnings from tornado.escape import native_str, parse_qs_bytes, utf8 from tornado.log import gen_log @@ -380,10 +381,15 @@ class HTTPServerRequest(object): """Returns True if this request supports HTTP/1.1 semantics. .. deprecated:: 4.0 - Applications are less likely to need this information with the - introduction of `.HTTPConnection`. If you still need it, access - the ``version`` attribute directly. + + Applications are less likely to need this information with + the introduction of `.HTTPConnection`. If you still need + it, access the ``version`` attribute directly. This method + will be removed in Tornado 6.0. + """ + warnings.warn("supports_http_1_1() is deprecated, use request.version instead", + DeprecationWarning) return self.version == "HTTP/1.1" @property @@ -412,8 +418,10 @@ class HTTPServerRequest(object): .. deprecated:: 4.0 Use ``request.connection`` and the `.HTTPConnection` methods - to write the response. + to write the response. This method will be removed in Tornado 6.0. """ + warnings.warn("req.write deprecated, use req.connection.write and write_headers instead", + DeprecationWarning) assert isinstance(chunk, bytes) assert self.version.startswith("HTTP/1."), \ "deprecated interface only supported in HTTP/1.x" @@ -424,8 +432,10 @@ class HTTPServerRequest(object): .. deprecated:: 4.0 Use ``request.connection`` and the `.HTTPConnection` methods - to write the response. + to write the response. This method will be removed in Tornado 6.0. """ + warnings.warn("req.finish deprecated, use req.connection.finish instead", + DeprecationWarning) self.connection.finish() self._finish_time = time.time() diff --git a/tornado/test/httpserver_test.py b/tornado/test/httpserver_test.py index b53dd8bfd..155dbebe8 100644 --- a/tornado/test/httpserver_test.py +++ b/tornado/test/httpserver_test.py @@ -1152,10 +1152,10 @@ class LegacyInterfaceTest(AsyncHTTPTestCase): request.connection.finish() return 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() + request.connection.write(utf8("HTTP/1.1 200 OK\r\n" + "Content-Length: %d\r\n\r\n" % len(message))) + request.connection.write(message) + request.connection.finish() return handle_request def test_legacy_interface(self): diff --git a/tornado/web.py b/tornado/web.py index 4f4277296..1c077fd21 100644 --- a/tornado/web.py +++ b/tornado/web.py @@ -1016,7 +1016,7 @@ class RequestHandler(object): self.request.connection.set_close_callback(None) self.flush(include_footers=True) - self.request.finish() + self.request.connection.finish() self._log() self._finished = True self.on_finish()