Skip to content

Commit a86348e

Browse files
committed
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.
1 parent eef32e2 commit a86348e

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

tornado/httputil.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import numbers
3030
import re
3131
import time
32+
import warnings
3233

3334
from tornado.escape import native_str, parse_qs_bytes, utf8
3435
from tornado.log import gen_log
@@ -380,10 +381,15 @@ def supports_http_1_1(self):
380381
"""Returns True if this request supports HTTP/1.1 semantics.
381382
382383
.. deprecated:: 4.0
383-
Applications are less likely to need this information with the
384-
introduction of `.HTTPConnection`. If you still need it, access
385-
the ``version`` attribute directly.
384+
385+
Applications are less likely to need this information with
386+
the introduction of `.HTTPConnection`. If you still need
387+
it, access the ``version`` attribute directly. This method
388+
will be removed in Tornado 6.0.
389+
386390
"""
391+
warnings.warn("supports_http_1_1() is deprecated, use request.version instead",
392+
DeprecationWarning)
387393
return self.version == "HTTP/1.1"
388394

389395
@property
@@ -412,8 +418,10 @@ def write(self, chunk, callback=None):
412418
413419
.. deprecated:: 4.0
414420
Use ``request.connection`` and the `.HTTPConnection` methods
415-
to write the response.
421+
to write the response. This method will be removed in Tornado 6.0.
416422
"""
423+
warnings.warn("req.write deprecated, use req.connection.write and write_headers instead",
424+
DeprecationWarning)
417425
assert isinstance(chunk, bytes)
418426
assert self.version.startswith("HTTP/1."), \
419427
"deprecated interface only supported in HTTP/1.x"
@@ -424,8 +432,10 @@ def finish(self):
424432
425433
.. deprecated:: 4.0
426434
Use ``request.connection`` and the `.HTTPConnection` methods
427-
to write the response.
435+
to write the response. This method will be removed in Tornado 6.0.
428436
"""
437+
warnings.warn("req.finish deprecated, use req.connection.finish instead",
438+
DeprecationWarning)
429439
self.connection.finish()
430440
self._finish_time = time.time()
431441

tornado/test/httpserver_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,10 +1152,10 @@ def handle_request(request):
11521152
request.connection.finish()
11531153
return
11541154
message = b"Hello world"
1155-
request.write(utf8("HTTP/1.1 200 OK\r\n"
1156-
"Content-Length: %d\r\n\r\n" % len(message)))
1157-
request.write(message)
1158-
request.finish()
1155+
request.connection.write(utf8("HTTP/1.1 200 OK\r\n"
1156+
"Content-Length: %d\r\n\r\n" % len(message)))
1157+
request.connection.write(message)
1158+
request.connection.finish()
11591159
return handle_request
11601160

11611161
def test_legacy_interface(self):

tornado/web.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,7 @@ def finish(self, chunk=None):
10161016
self.request.connection.set_close_callback(None)
10171017

10181018
self.flush(include_footers=True)
1019-
self.request.finish()
1019+
self.request.connection.finish()
10201020
self._log()
10211021
self._finished = True
10221022
self.on_finish()

0 commit comments

Comments
 (0)