aboutsummaryrefslogtreecommitdiffstats
path: root/src/gun_socks.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2019-09-20 12:19:33 +0200
committerLoïc Hoguin <[email protected]>2019-09-22 16:46:35 +0200
commitf75a5416c4979ca26b1fbb8a737def8d01a20c8b (patch)
tree78443cfad2e8eac2c26f7a153dde9216e4770481 /src/gun_socks.erl
parent02dd576a837b8b47b1c656c6f4b8769c1aeb4ed0 (diff)
downloadgun-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 'src/gun_socks.erl')
-rw-r--r--src/gun_socks.erl18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/gun_socks.erl b/src/gun_socks.erl
index 16684f8..6123953 100644
--- a/src/gun_socks.erl
+++ b/src/gun_socks.erl
@@ -16,6 +16,8 @@
-export([check_options/1]).
-export([name/0]).
+-export([opts_name/0]).
+-export([has_keepalive/0]).
-export([init/4]).
-export([switch_transport/3]).
-export([handle/4]).
@@ -78,6 +80,8 @@ check_auth_opt(Methods) ->
end.
name() -> socks.
+opts_name() -> socks_opts.
+has_keepalive() -> false.
init(Owner, Socket, Transport, Opts) ->
5 = Version = maps:get(version, Opts, 5),
@@ -116,8 +120,7 @@ handle(<<1, 0>>, State=#socks_state{version=5, status=auth_username_password}) -
handle(<<1, _>>, #socks_state{version=5, status=auth_username_password}) ->
{error, {socks5, username_password_auth_failure}};
%% Connect reply.
-handle(<<5, 0, 0, Rest0/bits>>, State=#socks_state{owner=Owner, socket=Socket, transport=Transport, opts=Opts,
- version=5, status=connect}) ->
+handle(<<5, 0, 0, Rest0/bits>>, #socks_state{opts=Opts, version=5, status=connect}) ->
%% @todo What to do with BoundAddr and BoundPort? Add as metadata to origin info?
{_BoundAddr, _BoundPort} = case Rest0 of
%% @todo Seen a server with <<1, 0:48>>.
@@ -139,16 +142,13 @@ handle(<<5, 0, 0, Rest0/bits>>, State=#socks_state{owner=Owner, socket=Socket, t
},
[{origin, <<"https">>, NewHost, NewPort, socks5},
{tls_handshake, HandshakeEvent, maps:get(protocols, Opts, [http])}];
- #{protocols := [{socks, SockOpts}]} ->
+ #{protocols := [Protocol={socks, _}]} ->
[{origin, <<"http">>, NewHost, NewPort, socks5},
- {switch_protocol, ?MODULE, init(Owner, Socket, Transport, SockOpts)}];
- #{protocols := [http2]} ->
- [{origin, <<"http">>, NewHost, NewPort, socks5},
- {switch_protocol, gun_http2, State},
- {mode, http}];
+ {switch_protocol, Protocol}];
_ ->
+ [Protocol] = maps:get(protocols, Opts, [http]),
[{origin, <<"http">>, NewHost, NewPort, socks5},
- {switch_protocol, gun_http, State},
+ {switch_protocol, Protocol},
{mode, http}]
end;
handle(<<5, Error, _/bits>>, #socks_state{version=5, status=connect}) ->