Skip to content

Commit 7d4c4cb

Browse files
authored
Merge pull request tornadoweb#2360 from bdarnell/httpserver-deprecation
httputil: Deprecate some server-side HTTP interfaces
2 parents 2b2a220 + a86348e commit 7d4c4cb

File tree

4 files changed

+28
-12
lines changed

4 files changed

+28
-12
lines changed

tornado/http1connection.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,14 @@ def _clear_callbacks(self):
277277
def set_close_callback(self, callback):
278278
"""Sets a callback that will be run when the connection is closed.
279279
280-
.. deprecated:: 4.0
281-
Use `.HTTPMessageDelegate.on_connection_close` instead.
280+
Note that this callback is slightly different from
281+
`.HTTPMessageDelegate.on_connection_close`: The
282+
`.HTTPMessageDelegate` method is called when the connection is
283+
closed while recieving a message. This callback is used when
284+
there is not an active delegate (for example, on the server
285+
side this callback is used if the client closes the connection
286+
after sending its request but before receiving all the
287+
response.
282288
"""
283289
self._close_callback = stack_context.wrap(callback)
284290

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)