Can someone help me get tls with hyper::client::conn

async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let target_stream = TcpStream::connect("").await?;

    let (mut request_sender, connection) = conn::handshake(target_stream).await?;

    // spawn a task to poll the connection and drive the HTTP state
    tokio::spawn(async move {
        if let Err(e) = connection.await {
            eprintln!("Error in connection: {}", e);

    let request = Request::builder()
        // We need to manually add the host header because SendRequest does not
        .header("Host", "")
    let response = request_sender.send_request(request).await?;
    assert!(response.status() == StatusCode::OK);


Hi guys, how can I add tls to this code, I know I could use hyper::client, or hyper_tls::httpsconnector,
But I want to know more about low-level stuff.

Thank you very much for your help.


I'm pretty sure you can just give the TcpStream to a tls library such as tokio-rustls or tokio-native-tls, which would give you a TlsStream. Then you can use it with conn::handshake normally.

1 Like

Hi Alice,

good to see you here. THank you very much for your help.

Best regards,