Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upclient: tunneling via CONNECT method example #1884
Comments
|
For anyone looking for a solution - I just made this for now: https://github.com/MOZGIII/http-proxy-client-async |
|
There's now an |
|
Niice! |
|
That is actually a server example, while I'm looking for a client example. I.e. I want my app to connect to somewhere using HTTP protocol with Please reopen. |
|
Oh, nvm, it's two in one. |
|
Ok, it's not. The code never establishes a connection to a third-party server via HTTP CONNECT proxy. It does implement tunneling for an HTTP proxy server. I need a client. |
|
Ah OK. As a starter, it'd be similar to this HTTP upgrades example, just setting |
|
Thanks, that's what I was looking for! |
|
Except, the |
|
If I recall correctly when I checked last time, the situation was the same: there was no way to get a raw stream from the body, and that was the blocker. |
|
I'm not sure I follow. Something like this should work: async fn client_tunnel(addr: SocketAddr) -> Result<()> {
let req = Request::builder()
.uri(format!("{}", addr))
.method("CONNECT")
.body(Body::empty())
.unwrap();
let res = Client::new().request(req).await?;
if res.status() != StatusCode::OK {
panic!("Our server didn't CONNECT: {}", res.status());
}
match res.into_body().on_upgrade().await {
Ok(upgraded) => {
if let Err(e) = client_upgraded_io(upgraded).await {
eprintln!("client foobar io error: {}", e)
};
}
Err(e) => eprintln!("upgrade error: {}", e),
}
Ok(())
} |
|
Why would |
|
It's the same fundamental mechanism, but the name "connect" is overloaded. It could also sound like a TCP connect. |
|
I'd name it |
|
Ok, maybe not |
|
If not - at least the documentation has to properly explain that the internal implementation is not coupled with I really like how Go does it - it's called |
I'd like to use
CONNECTmethod with HTTP (at least with 1.1, and, ideally with 2).However, I don't think there's a way to unwrap the underlying stream from HTTP response.
Practically, I need an object that implements
futures::io::AsyncReadandfutures::io::AsyncWrite(fromfutures0.3). Similar thing viatokioshould work too.