Skip to content

Commit

Permalink
RM old
Browse files Browse the repository at this point in the history
  • Loading branch information
synoet committed May 6, 2024
1 parent 3504979 commit 81a6a02
Showing 1 changed file with 0 additions and 47 deletions.
47 changes: 0 additions & 47 deletions theia/proxy-rs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,53 +216,6 @@ async fn handle(
(StatusCode::OK, "authorized".to_string())
}

async fn proxy(req: Request) -> Result<Response> {
let authority = req.uri().authority().map(|auth| auth.to_string());

let host_addr = match authority {
Some(addr) => addr,
None => {
return Ok((
StatusCode::BAD_REQUEST,
"CONNECT must be to a socket address",
)
.into_response());
}
};

tokio::task::spawn(async move {
match hyper::upgrade::on(req).await {
Ok(upgraded) => {
let res = tunnel(upgraded, host_addr).await;

if let Err(e) = res {
tracing::warn!("tunnel error: {}", e);
}
}
Err(e) => {
tracing::warn!("upgrade error: {}", e);
}
};
});

Ok(Response::new(Body::empty()))
}

async fn tunnel(upgraded: Upgraded, addr: String) -> anyhow::Result<()> {
let mut server = TcpStream::connect(addr).await?;
let mut upgraded = TokioIo::new(upgraded);

let (from_client, from_server) =
tokio::io::copy_bidirectional(&mut upgraded, &mut server).await?;

tracing::debug!(
"client wrote {} bytes and received {} bytes",
from_client,
from_server
);

Ok(())
}

#[tokio::main]
async fn main() {
Expand Down

0 comments on commit 81a6a02

Please sign in to comment.