diff options
author | Loïc Hoguin <[email protected]> | 2019-09-20 12:19:33 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2019-09-22 16:46:35 +0200 |
commit | f75a5416c4979ca26b1fbb8a737def8d01a20c8b (patch) | |
tree | 78443cfad2e8eac2c26f7a153dde9216e4770481 /test/socks_SUITE.erl | |
parent | 02dd576a837b8b47b1c656c6f4b8769c1aeb4ed0 (diff) | |
download | gun-f75a5416c4979ca26b1fbb8a737def8d01a20c8b.tar.gz gun-f75a5416c4979ca26b1fbb8a737def8d01a20c8b.tar.bz2 gun-f75a5416c4979ca26b1fbb8a737def8d01a20c8b.zip |
Supports going through multiple Socks proxies
This commit also reworks the switch_protocol command.
The `P | {P, Opts}` type is used here as well. This
allows us to remove the code specific to Websocket.
In addition a few new protocol functions allow us
to declare what's the name of the options key for
the protocol and what the capabilities are with
regard to keepalive.
Diffstat (limited to 'test/socks_SUITE.erl')
-rw-r--r-- | test/socks_SUITE.erl | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/test/socks_SUITE.erl b/test/socks_SUITE.erl index 9d80328..e565017 100644 --- a/test/socks_SUITE.erl +++ b/test/socks_SUITE.erl @@ -257,3 +257,57 @@ do_socks5(OriginScheme, OriginTransport, OriginProtocol, ProxyTransport, SocksAu protocol := socks }]} = gun:info(ConnPid), gun:close(ConnPid). + +socks5_through_multiple_proxies(_) -> + doc("Gun can be used to establish a TCP connection " + "to an HTTP/1.1 server via a tunnel going through " + "two separate Socks5 proxies."), + {ok, OriginPid, OriginPort} = init_origin(tcp, http), + {ok, Proxy1Pid, Proxy1Port} = do_proxy_start(tcp, none), + {ok, Proxy2Pid, Proxy2Port} = do_proxy_start(tcp, none), + Authority = iolist_to_binary(["localhost:", integer_to_binary(OriginPort)]), + {ok, ConnPid} = gun:open("localhost", Proxy1Port, #{ + protocols => [{socks, #{ + host => "localhost", + port => Proxy2Port, + protocols => [{socks, #{ + host => "localhost", + port => OriginPort + }}] + }}] + }), + %% We receive a gun_up and two gun_socks_connected. + {ok, socks} = gun:await_up(ConnPid), + {ok, socks} = gun:await_up(ConnPid), + {ok, http} = gun:await_up(ConnPid), + %% The first proxy received two packets. + {auth_methods, 1, [none]} = receive_from(Proxy1Pid), + {connect, <<"localhost">>, Proxy2Port} = receive_from(Proxy1Pid), + %% So did the second proxy. + {auth_methods, 1, [none]} = receive_from(Proxy2Pid), + {connect, <<"localhost">>, OriginPort} = receive_from(Proxy2Pid), + handshake_completed = receive_from(OriginPid), + _ = gun:get(ConnPid, "/proxied"), + Data = receive_from(OriginPid), + Lines = binary:split(Data, <<"\r\n">>, [global]), + [<<"host: ", Authority/bits>>] = [L || <<"host: ", _/bits>> = L <- Lines], + #{ + transport := tcp, + protocol := http, + origin_scheme := <<"http">>, + origin_host := "localhost", + origin_port := OriginPort, + intermediaries := [#{ + type := socks5, + host := "localhost", + port := Proxy1Port, + transport := tcp, + protocol := socks + }, #{ + type := socks5, + host := "localhost", + port := Proxy2Port, + transport := tcp, + protocol := socks + }]} = gun:info(ConnPid), + gun:close(ConnPid). |