tungstenite-rs icon indicating copy to clipboard operation
tungstenite-rs copied to clipboard

Is there any support for proxies?

Open JakkuSakura opened this issue 4 years ago • 17 comments

I can only access the dest host on another machine by ssh. If I can access it via proxy, it will be much convenient. How can I do it for tungstenite?

JakkuSakura avatar Feb 14 '21 16:02 JakkuSakura

Do you have an option to use SSH TCP tunnelling?

strohel avatar Feb 15 '21 17:02 strohel

Yes I can use it, but I have many different websocket addresses, so SSH TCP tunnelling is not very convenient.

JakkuSakura avatar Feb 16 '21 15:02 JakkuSakura

We thought about making one of our internal libraries public (it brings support for proxies and supports such auth methods as basic, digest, ntlm, negotiate via SSPI / GSSAPI), but the support for proxies and their authentication methods should be part of another crate. We could introduce a proxy feature though that could rely on another crate for proxy and proxy authentication.

I actually believe we've discussed it somewhere in issues here, but can't find the discussion by just quick search for proxies (perhaps it was in one or another PR)

daniel-abramov avatar Feb 26 '21 14:02 daniel-abramov

I created a branch that supports sock5 proxy in my forked repo, which may be helpful to you. pub fn connect_with_proxy

PrivateRookie avatar Mar 14 '21 14:03 PrivateRookie

Actually I guess support for http/https proxy will be more useful. As I write in https://github.com/snapview/tokio-tungstenite/issues/168, to inspect secure websocket connections, the best way is to use some mitm proxy software, which requires the client to send domain (HTTP GET request) rather than resolved ip address. And BTW it also requires support for specifying custom CA certificate, to allow mitm work.

For client behind firewall and only proxy allowed, there are many workarounds, such as using gost to convert almost any proxy protocol to a transparent one, as long as one don't need to inspect the raw stream or the target is plain, unsecured websocket. Still crate level support is always better, for crate users.

runapp avatar May 04 '21 15:05 runapp

Since we can use any stream that implementes Read and Write(or Async version), a proxy connection like async_socks5 would suffice.

JakkuSakura avatar May 07 '21 17:05 JakkuSakura

Since we can use any stream that implementes Read and Write(or Async version), a proxy connection like async_socks5 would suffice.

I had a quick look at it and it seems like you can combine these easily, i.e. just use the async_sock5 to connect to the proxy and then pass the "upgraded" stream to the client() or something.

daniel-abramov avatar May 10 '21 09:05 daniel-abramov

good question, any solutions?

guotie avatar Sep 10 '21 07:09 guotie

It would be great to support system proxies like reqwest does, which can be utilized by Docker easily without change the code.

siegfried avatar Dec 13 '21 10:12 siegfried

Yes, it could have been more convenient, but reqwest is by its nature a batteries included wrapper around HTTP, whereas tungstenite-rs is more like a core for support of WebSockets with optional blocking implementation for quick/typical use cases. tungstenite-rs is more akin to hyper in this regard rather than to reqwest if I can put it like this.

daniel-abramov avatar Jan 04 '22 18:01 daniel-abramov

@siegfried what makes them so "system"? Is HTTP_PROXY a standard well-known env var that a lot of software expects to be set systemwide?

qm3ster avatar Feb 26 '22 23:02 qm3ster

@siegfried what makes them so "system"? Is HTTP_PROXY a standard well-known env var that a lot of software expects to be set systemwide?

Supported by CURL, Docker, wget and reqwest. Call it "standard", "convention" or whatever you like. Not interested at the definition debate. I agree with what @application-developer-DA said.

siegfried avatar Feb 27 '22 00:02 siegfried

so, any solution can solve the proxy problems?

Praying avatar Mar 25 '22 05:03 Praying

so, any solution can solve the proxy problems?

@Praying depends on the type of proxy. Here's secure websocket over HTTPS proxy: https://github.com/websockets-rs/rust-websocket/issues/258#issuecomment-1052801655

qm3ster avatar Mar 25 '22 15:03 qm3ster

In particular, since both that approach and async_socks5::connect leave you with an un-wrapped tokio::net::TcpSocket or whatever else you had, you can easily handle HTTP_PROXY values of http:// and socks5://, or lack thereof, without any dyn, enums, or generics. Only what you do on the socket before passing it to tokio_tungstenite::client_async_tls changes!

qm3ster avatar Mar 25 '22 17:03 qm3ster

FYI. I'm using async-http-proxy with async-tungstenite and works well for general HTTP proxy (not SOCK5). I remember that the feature was tested with nginx, squid, haproxy, and proxy.py

lambdalisue avatar Apr 18 '22 03:04 lambdalisue