New GitHub issue #118642 from Dreamsorcerer:<br>

<hr>

<pre>
# Feature or enhancement

### Proposal:

Currently there doesn't seem to be any way to flush the asyncio.StreamReader buffer, or interact with the state of the buffer. It seems that all methods will wait for data to arrive if the buffer does not have enough data.

>From my understanding of STARTTLS, this makes it difficult to implement securely. With STARTTLS we start with an insecure connection, and then when we complete the TLS handshake any other data that was received must be discarded. Failure to do so can result in previously sent commands being acted upon as part of the encrypted session.

To make this work correctly, it seems there would need to be a flush()/empty() method, a method to read from the buffer without blocking on new data, or a method to check how much data is currently in the buffer.

https://tools.ietf.org/html/rfc3207#page-7
https://nostarttls.secvuln.info/

### Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

### Links to previous discussion of this feature:

_No response_
</pre>

<hr>

<a href="https://github.com/python/cpython/issues/118642">View on GitHub</a>
<p>Labels: type-feature</p>
<p>Assignee: </p>