]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
httputil: Deprecate old interfaces 2360/head
authorBen Darnell <ben@bendarnell.com>
Sat, 21 Apr 2018 21:01:32 +0000 (17:01 -0400)
committerBen Darnell <ben@bendarnell.com>
Sat, 21 Apr 2018 21:11:10 +0000 (17:11 -0400)
This is mainly preparation for HTTP/2: request.write was designed to
mix headers and bodies in a way that is no longer supported.

tornado/httputil.py
tornado/test/httpserver_test.py
tornado/web.py

index 3d2d3359d745bf95f558b1fe805bfdad5e7283fc..9c607b8c853aa896c863f0a72cd58683734b79b0 100644 (file)
@@ -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()
 
index b53dd8bfdba23cee396c837541c55eca5895655b..155dbebe8ecf15a318fbe9f0f02d7bf6ff1819c8 100644 (file)
@@ -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):
index 4f42772962415b6a038275ac5eab9c2f48f0a95b..1c077fd21b5243190c2783159675caa0083c4fe7 100644 (file)
@@ -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()