ptth/crates/ptth_forwarding/src/main.rs

25 lines
528 B
Rust

use reqwest::Client;
use tokio::{
io::AsyncWriteExt,
net::TcpStream,
stream::StreamExt,
};
#[tokio::main]
async fn main () -> anyhow::Result <()> {
let client = Client::builder ()
.build ()?;
let mut tcp_stream = TcpStream::connect ("127.0.0.1:4010").await?;
let resp = client.get ("http://127.0.0.1:4003/").send ().await?;
let mut downstream = resp.bytes_stream ();
while let Some (Ok (item)) = downstream.next ().await {
println! ("Chunk: {:?}", item);
tcp_stream.write_all (&item).await?;
}
Ok (())
}