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

HTTP Client with KeepAlive #7

Closed
yoshuawuyts opened this issue Nov 10, 2019 · 1 comment
Closed

HTTP Client with KeepAlive #7

yoshuawuyts opened this issue Nov 10, 2019 · 1 comment

Comments

@yoshuawuyts
Copy link
Member

Moving the conversation from #1 here; @dignifiedquire proposed we build an HTTP client like so:

async fn main() -> throws {
    let tcp_stream = net::TcpStream::connect("127.0.0.1:8080").await?;
    let (tcp_reader, tcp_writer) = &mut (&tcp_stream, &tcp_stream);

    let http_stream = client::connect(tcp_reader);

    // lets make 10 requests, with the same connection
    for i in 0..10 {
        // Send a response
        let body = Body::from(format!("hello chashu {}", i));
        let mut req = client::encode(Request::new(body));
        tcp_writer.write_all(req).await?;

        // read the response
        let res = http_stream.next().await?;
        println!("Response {}: {:?}", i, res);
    }
}
@yoshuawuyts yoshuawuyts changed the title HTTP Client HTTP Client with KeepAlive Nov 10, 2019
@yoshuawuyts
Copy link
Member Author

done!

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

1 participant