quininer / tokio-rustls

Asynchronous TLS/SSL streams for Tokio using Rustls.
142 stars 38 forks source link

Reading TlsStream? #60

Closed tuboythers closed 4 years ago

tuboythers commented 4 years ago

Hey,

I may be missing something, but one thing is not clear to me, how would one be able to read the TLS stream so they could parse the requests towards the server (headers, upgrades, etc.)? If I extract and read() from the TcpStream, the request converted in utf8 is in non-readable format, so I believe, rustls rectifies that with the read_tls() function, but it's not very clear to me how to implement that.

So, I am asking for some pointers, based on your server example, what would you do from line 72 onwards: let mut stream = acceptor.accept(stream).await?; to be able to read the tls stream?

quininer commented 4 years ago

You can read it like any AsyncRead.

If I extract and read() from the TcpStream, the request converted in utf8 is in non-readable format,

I think this is weird, maybe you are using http2?

tuboythers commented 4 years ago

Funny thing is I never realized I could do that, haha, sorry. I was doing this instead:

let mut acceptor = acceptor.accept(socket).await;

                    match acceptor {
                        Ok(mut tls_stream) => {

                            let (mut tcp_stream, mut tls_session) = tls_stream.get_mut()
...

And reading from the raw tcp_stream instead of the tls_stream, hence the confusion. Thanks for clearing that up!