Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[question] TlsStreams with async-h1 #138

Open
Firstyear opened this issue Aug 30, 2020 · 1 comment
Open

[question] TlsStreams with async-h1 #138

Firstyear opened this issue Aug 30, 2020 · 1 comment

Comments

@Firstyear
Copy link

Firstyear commented Aug 30, 2020

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 :)

@jbr
Copy link
Member

jbr commented Aug 30, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants