gh-79156: Add start_tls() method to streams API (#91453)

The existing event loop `start_tls()` method is not sufficient for
connections using the streams API. The existing StreamReader works
because the new transport passes received data to the original protocol.
The StreamWriter must then write data to the new transport, and the
StreamReaderProtocol must be updated to close the new transport
correctly.

The new StreamWriter `start_tls()` updates itself and the reader
protocol to the new SSL transport.

Co-authored-by: Ian Good <icgood@gmail.com>
This commit is contained in:
Oleg Iarygin 2022-04-15 15:23:14 +03:00 committed by GitHub
parent bd26ef5e9e
commit 6217864fe5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 109 additions and 0 deletions

View file

@ -295,6 +295,24 @@ StreamWriter
be resumed. When there is nothing to wait for, the :meth:`drain`
returns immediately.
.. coroutinemethod:: start_tls(sslcontext, \*, server_hostname=None, \
ssl_handshake_timeout=None)
Upgrade an existing stream-based connection to TLS.
Parameters:
* *sslcontext*: a configured instance of :class:`~ssl.SSLContext`.
* *server_hostname*: sets or overrides the host name that the target
server's certificate will be matched against.
* *ssl_handshake_timeout* is the time in seconds to wait for the TLS
handshake to complete before aborting the connection. ``60.0`` seconds
if ``None`` (default).
.. versionadded:: 3.8
.. method:: is_closing()
Return ``True`` if the stream is closed or in the process of