Hyper : read/write tcp stream after HTTP tunnel is established


hyper crate version 0.13

let req = Request::connect(uri)

let client = Client::builder().build(HttpConnector::new()));
let resp = match client.request(req).await {
    Err(e) => {
        let msg = format!("HTTP tunnel cannot be established. {}", e);
        error!("{}", &msg);
        return Err(io::Error::new(io::ErrorKind::NotConnected, msg));
    Ok(resp) => resp

if resp.status() != StatusCode::OK {
    let msg = format!("CONNECT {} responsed HTTP {}", uri, resp.status());
    error!("{}", &msg);
    return Err(io::Error::new(io::ErrorKind::PermissionDenied, msg));

// now HTTP tunnel is established, how can I read/write to tcp stream in resp?

Thank you

With hyper you are supposed to provide the body of the request using the Body type up front. One option would be to use the channel constructor, which allows you to write chunks to the body later.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.