aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2020-09-21 13:23:02 +0200
committerLoïc Hoguin <[email protected]>2020-09-21 15:52:26 +0200
commit920afa71ac298032b376753594133c98bd36d04a (patch)
tree76e412079baf37f4c15ec6ebabcd06793b15d7c3 /src
parent43df59e49b1ab92e3ca0a333ae403742b2ed7a5d (diff)
downloadgun-920afa71ac298032b376753594133c98bd36d04a.tar.gz
gun-920afa71ac298032b376753594133c98bd36d04a.tar.bz2
gun-920afa71ac298032b376753594133c98bd36d04a.zip
Fix compilation and Dialyzer warnings
Diffstat (limited to 'src')
-rw-r--r--src/gun.erl1
-rw-r--r--src/gun_http2.erl11
-rw-r--r--src/gun_tls_proxy_http2_connect.erl2
-rw-r--r--src/gun_tunnel.erl27
4 files changed, 20 insertions, 21 deletions
diff --git a/src/gun.erl b/src/gun.erl
index 4178c24..ea599bf 100644
--- a/src/gun.erl
+++ b/src/gun.erl
@@ -186,6 +186,7 @@
origin_port => inet:port_number(),
%% Non-stream intermediaries (for example SOCKS).
+ %% @todo I think this is not used anymore.
intermediaries => [intermediary()]
}.
-export_type([tunnel_info/0]).
diff --git a/src/gun_http2.erl b/src/gun_http2.erl
index 65b92e2..98a7e6c 100644
--- a/src/gun_http2.erl
+++ b/src/gun_http2.erl
@@ -418,7 +418,6 @@ headers_frame(State0=#http2_state{transport=Transport, opts=Opts,
#tunnel{destination=Destination, info=TunnelInfo0} = Tunnel,
#{host := DestHost, port := DestPort} = Destination,
TunnelInfo = TunnelInfo0#{
- transport => maps:get(transport, Destination, tcp),
origin_host => DestHost,
origin_port => DestPort
},
@@ -1040,8 +1039,10 @@ timeout(State=#http2_state{http2_machine=HTTP2Machine0}, {cow_http2_machine, Nam
stream_info(State, StreamRef) when is_reference(StreamRef) ->
case get_stream_by_ref(State, StreamRef) of
- #stream{reply_to=ReplyTo, tunnel=#tunnel{protocol=Proto, protocol_state=ProtoState,
- info=#{transport := Transport, origin_host := OriginHost, origin_port := OriginPort}}} ->
+ #stream{reply_to=ReplyTo, tunnel=#tunnel{destination=Destination,
+ info=#{origin_host := OriginHost, origin_port := OriginPort},
+ protocol=Proto, protocol_state=ProtoState}} ->
+ Transport = maps:get(transport, Destination, tcp),
{ok, #{
ref => StreamRef,
reply_to => ReplyTo,
@@ -1072,10 +1073,6 @@ stream_info(State, StreamRefList=[StreamRef|Tail]) ->
#stream{tunnel=#tunnel{protocol=Proto, protocol_state=ProtoState}} ->
%% We must return the real StreamRef as seen by the user.
%% We therefore set it on return, with the outer layer "winning".
- %%
- %% We also add intermediaries which are prepended to the list and
- %% therefore are ultimately given from outer to inner layer just
- %% like gun:info/1 intermediaries.
case Proto:stream_info(ProtoState, normalize_stream_ref(Tail)) of
{ok, undefined} ->
{ok, undefined};
diff --git a/src/gun_tls_proxy_http2_connect.erl b/src/gun_tls_proxy_http2_connect.erl
index 70b4824..97cbcd7 100644
--- a/src/gun_tls_proxy_http2_connect.erl
+++ b/src/gun_tls_proxy_http2_connect.erl
@@ -50,7 +50,7 @@ connect(_, _, _, _) ->
error(not_implemented).
-spec send(socket(), iodata()) -> ok.
-send(S=#{gun_pid := GunPid, reply_to := ReplyTo, stream_ref := DataStreamRef,
+send(#{gun_pid := GunPid, reply_to := ReplyTo, stream_ref := DataStreamRef,
handle_continue_stream_ref := StreamRef}, Data) ->
GunPid ! {handle_continue, StreamRef, {data, ReplyTo, DataStreamRef, nofin, Data}},
ok.
diff --git a/src/gun_tunnel.erl b/src/gun_tunnel.erl
index 6df4baa..7e8d4ef 100644
--- a/src/gun_tunnel.erl
+++ b/src/gun_tunnel.erl
@@ -37,13 +37,14 @@
-record(tunnel_state, {
%% Fake socket and transport.
+ %% We accept 'undefined' only to simplify the init code.
socket = undefined :: #{
gun_pid := pid(),
reply_to := pid(),
stream_ref := gun:stream_ref(),
handle_continue_stream_ref := gun:stream_ref()
- } | pid(),
- transport = undefined :: gun_tcp_proxy | gun_tls_proxy,
+ } | pid() | undefined,
+ transport = undefined :: gun_tcp_proxy | gun_tls_proxy | undefined,
%% The stream_ref from which the stream was created. When
%% the tunnel exists as a result of HTTP/2 CONNECT -> HTTP/1.1 CONNECT
@@ -82,7 +83,7 @@
%% We keep the new information to provide it in TunnelInfo of
%% the new protocol when the switch occurs.
protocol_origin = undefined :: undefined
- | {origin, binary(), binary(), binary(), connect | socks5}
+ | {origin, binary(), inet:hostname() | inet:ip_address(), inet:port_number(), connect | socks5}
}).
%% Socket is the "origin socket" and Transport the "origin transport".
@@ -116,18 +117,17 @@ init(ReplyTo, OriginSocket, OriginTransport, Opts=#{stream_ref := StreamRef, tun
%% We can't initialize the protocol until the TLS handshake has completed.
#{handshake_event := HandshakeEvent, protocols := Protocols} ->
#{handle_continue_stream_ref := ContinueStreamRef} = OriginSocket,
- %% @todo FIX THIS!!
- % #{
- % origin_host := DestHost,
- % origin_port := DestPort
- % } = TunnelInfo,
+ #{
+ origin_host := DestHost,
+ origin_port := DestPort
+ } = TunnelInfo,
%% @todo OK so Protocol:init/4 will need to have EvHandler/EvHandlerState!
%% Otherwise we can't do the TLS events.
#{
tls_opts := TLSOpts,
timeout := TLSTimeout
} = HandshakeEvent,
- {ok, ProxyPid} = gun_tls_proxy:start_link("fake", 12345,% @todo FIX THIS!! DestHost, DestPort,
+ {ok, ProxyPid} = gun_tls_proxy:start_link(DestHost, DestPort,
TLSOpts, TLSTimeout, OriginSocket, gun_tls_proxy_http2_connect,
{handle_continue, ContinueStreamRef, HandshakeEvent, Protocols}),
{tunnel, State#tunnel_state{socket=ProxyPid, transport=gun_tls_proxy,
@@ -199,7 +199,7 @@ handle_continue(ContinueStreamRef, {gun_tls_proxy, ProxyPid, {error, _Reason},
{[], EvHandlerState0};
%% Send the data. This causes TLS to encrypt the data and send it to the inner layer.
handle_continue(ContinueStreamRef, {data, _ReplyTo, _StreamRef, IsFin, Data},
- #tunnel_state{socket=Socket, transport=Transport}, _EvHandler, EvHandlerState)
+ #tunnel_state{}, _EvHandler, EvHandlerState)
when is_reference(ContinueStreamRef) ->
{[{send, IsFin, Data}], EvHandlerState};
handle_continue(ContinueStreamRef, {tls_proxy, ProxyPid, Data},
@@ -305,7 +305,7 @@ cancel(_State, _StreamRef, _ReplyTo, _EvHandler, _EvHandlerState) ->
timeout(_State, {cow_http2_machine, _Name}, _TRef) ->
todo.
-stream_info(State=#tunnel_state{transport=Transport, type=Type,
+stream_info(State=#tunnel_state{type=Type,
tunnel_transport=IntermediaryTransport, tunnel_protocol=IntermediaryProtocol,
info=TunnelInfo, protocol=Proto, protocol_state=ProtoState}, StreamRef0) ->
StreamRef = maybe_dereference(State, StreamRef0),
@@ -350,7 +350,8 @@ commands([{state, ProtoState}|Tail], State) ->
%% @todo We must pass down the set_cookie commands. Have a commands_queue.
commands([_SetCookie={set_cookie, _, _, _, _}|Tail], State=#tunnel_state{}) ->
commands(Tail, State);
-commands([{send, IsFin, Data}|Tail], State=#tunnel_state{socket=Socket, transport=Transport}) ->
+%% @todo What to do about IsFin?
+commands([{send, _IsFin, Data}|Tail], State=#tunnel_state{socket=Socket, transport=Transport}) ->
Transport:send(Socket, Data),
commands(Tail, State);
commands([Origin={origin, _Scheme, _NewHost, _NewPort, _Type}|Tail], State) ->
@@ -450,7 +451,7 @@ continue_stream_ref(#tunnel_state{tls_origin_socket=#{handle_continue_stream_ref
true -> [ContinueStreamRef]
end.
-maybe_dereference(#tunnel_state{stream_ref=RealStreamRef,
+maybe_dereference(#tunnel_state{stream_ref=_RealStreamRef,
type=connect, protocol=gun_tunnel}, [_StreamRef|Tail]) ->
%% @todo Assert that we got the right stream.
% StreamRef = if is_list(RealStreamRef) -> lists:last(RealStreamRef); true -> RealStreamRef end,