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

Is there any support for proxies? #177

Open
JakkuSakura opened this issue Feb 14, 2021 · 17 comments
Open

Is there any support for proxies? #177

JakkuSakura opened this issue Feb 14, 2021 · 17 comments

Comments

@JakkuSakura
Copy link

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?

@strohel
Copy link
Contributor

strohel commented Feb 15, 2021

Do you have an option to use SSH TCP tunnelling?

@JakkuSakura
Copy link
Author

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

@daniel-abramov
Copy link
Member

daniel-abramov commented Feb 26, 2021

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)

@PrivateRookie
Copy link

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

@runapp
Copy link

runapp commented May 4, 2021

Actually I guess support for http/https proxy will be more useful. As I write in snapview/tokio-tungstenite#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.

@JakkuSakura
Copy link
Author

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

@daniel-abramov
Copy link
Member

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.

@guotie
Copy link

guotie commented Sep 10, 2021

good question, any solutions?

@siegfried
Copy link

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

@daniel-abramov
Copy link
Member

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.

@qm3ster
Copy link

qm3ster commented Feb 26, 2022

@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?

@siegfried
Copy link

siegfried commented Feb 27, 2022

@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.

@Praying
Copy link

Praying commented Mar 25, 2022

so, any solution can solve the proxy problems?

@qm3ster
Copy link

qm3ster commented Mar 25, 2022

so, any solution can solve the proxy problems?

@Praying depends on the type of proxy. Here's secure websocket over HTTPS proxy: websockets-rs/rust-websocket#258 (comment)

@qm3ster
Copy link

qm3ster commented Mar 25, 2022

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!

@lambdalisue
Copy link

lambdalisue commented Apr 18, 2022

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

@chuxi
Copy link

chuxi commented Dec 15, 2022

I resolved the problem with reference from reqwest proxy implementation and make up all the details in my post
websocket

copy the InnerProxy and ProxyStream in your websocket client wrapper file. I did not supply it as library, because maybe the tungstenite will support the feature.

please use tokio-tungstenite

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests