async-h1 icon indicating copy to clipboard operation
async-h1 copied to clipboard

[question] TlsStreams with async-h1

Open Firstyear opened this issue 5 years ago • 1 comments

Hi there,

Please consider this more of a question than a bug report. I am trying to implement a TLS listener with tide, which requires me to implement a ToListener/Listener. For this to work I need to be able to implement a similar pattern as found in the tide unix listener such as:

fn handle_unix<State: Clone + Send + Sync + 'static>(app: Server<State>, stream: UnixStream) {
    task::spawn(async move {
        let local_addr = unix_socket_addr_to_string(stream.local_addr());
        let peer_addr = unix_socket_addr_to_string(stream.peer_addr());

        let fut = async_h1::accept(stream, |mut req| async {
            req.set_local_addr(local_addr.as_ref());
            req.set_peer_addr(peer_addr.as_ref());
            app.respond(req).await
        });

        if let Err(error) = fut.await {
            log::error!("async-h1 error", { error: error.to_string() });
        }
    });
}

The issue that I'm having is that async_h1::accept requires trait bounds of Clone, future::io::AsyncRead and future::io::AsyncWrite. I have noticed though that tokio_openssl and tokio-native-tls both implement only tokio::io::AsyncRead and AsyncWrite which are not compatible to the future::io versions. As well neither tokio openssl or native-tls are Clone on the resulting TlsStream.

So I think my question is:

  • Is there a current rust library that implements the future::io versions of AsyncRead and allows a TLS stream for use with async_h1::accept?
  • What's the best way to find or search for things that would or do implement these traits?
  • Are there any known examples of TLS + async_h1 that I can reference?
  • What would be required to allow async_h1 to work with tokio_openssl OR what would need to change in tokio_openssl to allow it to work with tide + async_h1

Anyway, thanks very much for your time :)

Firstyear avatar Aug 30 '20 01:08 Firstyear

I'll follow up in a little bit with more details, but check out https://github.com/http-rs/tide-rustls

jbr avatar Aug 30 '20 03:08 jbr