aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2019-09-19 15:14:31 +0200
committerLoïc Hoguin <[email protected]>2019-09-22 16:46:35 +0200
commit02dd576a837b8b47b1c656c6f4b8769c1aeb4ed0 (patch)
treeb405a4fc250ce60c7ee2fdba5e29858c54df8c4a /src
parent617554f305dc3bd031779ba0b8ef8d52edb52edd (diff)
downloadgun-02dd576a837b8b47b1c656c6f4b8769c1aeb4ed0.tar.gz
gun-02dd576a837b8b47b1c656c6f4b8769c1aeb4ed0.tar.bz2
gun-02dd576a837b8b47b1c656c6f4b8769c1aeb4ed0.zip
Add Socks5->HTTP/2 tests
Also consolidate the ALPN code in the tls_handshake state rather than doing it in CONNECT/Socks separately. Also improves the origin tests by sending a message once the handshake is completed instead of having timeouts.
Diffstat (limited to 'src')
-rw-r--r--src/gun.erl28
1 files changed, 14 insertions, 14 deletions
diff --git a/src/gun.erl b/src/gun.erl
index a6c1edc..3802ee0 100644
--- a/src/gun.erl
+++ b/src/gun.erl
@@ -962,10 +962,14 @@ tls_handshake(internal, {tls_handshake, HandshakeEvent, Protocols},
end;
%% TLS over TLS.
tls_handshake(internal, {tls_handshake,
- HandshakeEvent0=#{tls_opts := TLSOpts, timeout := TLSTimeout}, Protocols},
+ HandshakeEvent0=#{tls_opts := TLSOpts0, timeout := TLSTimeout}, Protocols},
State=#state{socket=Socket, transport=gun_tls, origin_host=OriginHost, origin_port=OriginPort,
event_handler=EvHandler, event_handler_state=EvHandlerState0}) ->
- HandshakeEvent = HandshakeEvent0#{socket => Socket},
+ TLSOpts = ensure_alpn(Protocols, TLSOpts0),
+ HandshakeEvent = HandshakeEvent0#{
+ tls_opts => TLSOpts,
+ socket => Socket
+ },
EvHandlerState = EvHandler:tls_handshake_start(HandshakeEvent, EvHandlerState0),
{ok, ProxyPid} = gun_tls_proxy:start_link(OriginHost, OriginPort,
TLSOpts, TLSTimeout, Socket, gun_tls, {HandshakeEvent, Protocols}),
@@ -1003,8 +1007,12 @@ tls_handshake(Type, Event, State) ->
handle_common_connected(Type, Event, ?FUNCTION_NAME, State).
normal_tls_handshake(Socket, State=#state{event_handler=EvHandler, event_handler_state=EvHandlerState0},
- HandshakeEvent0=#{tls_opts := TLSOpts, timeout := TLSTimeout}, Protocols) ->
- HandshakeEvent = HandshakeEvent0#{socket => Socket},
+ HandshakeEvent0=#{tls_opts := TLSOpts0, timeout := TLSTimeout}, Protocols) ->
+ TLSOpts = ensure_alpn(Protocols, TLSOpts0),
+ HandshakeEvent = HandshakeEvent0#{
+ tls_opts => TLSOpts,
+ socket => Socket
+ },
EvHandlerState1 = EvHandler:tls_handshake_start(HandshakeEvent, EvHandlerState0),
case gun_tls:connect(Socket, TLSOpts, TLSTimeout) of
{ok, TLSSocket} ->
@@ -1068,7 +1076,7 @@ connected(cast, {connect, ReplyTo, StreamRef, Destination0, Headers, InitialFlow
State=#state{protocol=Protocol, protocol_state=ProtoState}) ->
%% The protocol option has been deprecated in favor of the protocols option.
%% Nobody probably ended up using it, but let's not break the interface.
- Destination1 = case Destination0 of
+ Destination = case Destination0 of
#{protocols := _} ->
Destination0;
#{protocol := DestProto} ->
@@ -1076,14 +1084,6 @@ connected(cast, {connect, ReplyTo, StreamRef, Destination0, Headers, InitialFlow
_ ->
Destination0
end,
- Destination = case Destination1 of
- #{transport := tls} ->
- Destination1#{tls_opts => ensure_alpn(
- maps:get(protocols, Destination1, [http]),
- maps:get(tls_opts, Destination1, []))};
- _ ->
- Destination1
- end,
ProtoState2 = Protocol:connect(ProtoState, StreamRef, ReplyTo, Destination, Headers, InitialFlow),
{keep_state, State#state{protocol_state=ProtoState2}};
%% Public Websocket interface.
@@ -1326,7 +1326,7 @@ commands([TLSHandshake={tls_handshake, _, _}], State) ->
{next_event, internal, TLSHandshake}};
%% Switch from not_fully_connected to connected.
commands([{mode, http}], State) ->
- {next_state, connected, State}.
+ {next_state, connected, active(State)}.
disconnect(State0=#state{owner=Owner, status=Status, opts=Opts,
socket=Socket, transport=Transport,