How do I use gun with Socks5 proxy?
rdtq opened this issue ยท 2 comments
rdtq commented
I've been trying to setup this for a few days now
I'm using gun with Elixir project.
Here's my code (roughly translated from the docs here https://ninenines.eu/docs/en/gun/1.3/manual/gun.connect/#_examples ):
{:ok, pid} = :gun.open('socks5server.net', 1080)
:gun.await_up(pid)
stream = :gun.connect(pid, %{host: 'www.bing.com', port: 443, protocols: [:http], transport: :tls})
:gun.await(pid, stream)
stream2 = :gun.get(pid, '/')
:gun.await(pid, stream2)
:gun.stream_info(pid, stream2)
body = :gun.await_body(pid, stream2)
What I get is:
{:error, :timeout}
Am I using gun wrong?
essen commented
You have to configure the socks protocol. gun:connect
is for HTTP CONNECT.
https://github.com/ninenines/gun/blob/master/test/socks_SUITE.erl#L215-L224 for example.
It's for 2.0 but it's not super different for 1.3, not sure anything even changed.
rdtq commented
Thanks! What worked for me was
{:ok, socks_conn} = :gun.open('socks5server.net', 1080, %{transport: :tcp, protocols: [{:socks, %{host: 'bing.com', port: 443, transport: :tls}}]})