aboutsummaryrefslogtreecommitdiffstats
path: root/src/gun_http.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2019-04-19 13:09:50 +0200
committerLoïc Hoguin <[email protected]>2019-04-19 13:09:50 +0200
commiteecb5e76eca90ebbd97f24e79282444fa27bf508 (patch)
treecbcbe5ef7d156912621546d14d0375a660e8dcdf /src/gun_http.erl
parent6d0ea34ebe7cac66e3f25a018883c104c7fc31b6 (diff)
downloadgun-eecb5e76eca90ebbd97f24e79282444fa27bf508.tar.gz
gun-eecb5e76eca90ebbd97f24e79282444fa27bf508.tar.bz2
gun-eecb5e76eca90ebbd97f24e79282444fa27bf508.zip
Integrate gun_tls_proxy into gun proper
Still need to add ALPN support and to wait before trying to send data on a proxied TLS connection that didn't complete its handshake.
Diffstat (limited to 'src/gun_http.erl')
-rw-r--r--src/gun_http.erl15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/gun_http.erl b/src/gun_http.erl
index 719307c..efcea35 100644
--- a/src/gun_http.erl
+++ b/src/gun_http.erl
@@ -202,8 +202,8 @@ handle(Data, State=#http_state{in={body, Length}, connection=Conn}) ->
end
end.
-handle_head(Data, State=#http_state{socket=Socket, version=ClientVersion,
- content_handlers=Handlers0, connection=Conn,
+handle_head(Data, State=#http_state{socket=Socket, transport=Transport,
+ version=ClientVersion, content_handlers=Handlers0, connection=Conn,
streams=[Stream=#stream{ref=StreamRef, reply_to=ReplyTo,
method=Method, is_alive=IsAlive}|Tail]}) ->
{Version, Status, _, Rest} = cow_http:parse_status_line(Data),
@@ -226,6 +226,17 @@ handle_head(Data, State=#http_state{socket=Socket, version=ClientVersion,
NewHost = maps:get(host, Destination),
NewPort = maps:get(port, Destination),
case Destination of
+ #{transport := tls} when Transport =:= gun_tls ->
+ TLSOpts = maps:get(tls_opts, Destination, []),
+ TLSTimeout = maps:get(tls_handshake_timeout, Destination, infinity),
+ {ok, ProxyPid} = gun_tls_proxy:start_link(NewHost, NewPort,
+ TLSOpts, TLSTimeout, Socket, gun_tls),
+ [{state, State2#http_state{socket=ProxyPid, transport=gun_tls_proxy}},
+ {origin, <<"https">>, NewHost, NewPort, connect},
+ {switch_transport, gun_tls_proxy, ProxyPid}];
+ %% @todo Might also need to switch protocol, but gotta wait
+ %% @todo for the TLS connection to be established first.
+ %% @todo Should have a gun_tls_proxy event indicating connection success.
#{transport := tls} ->
TLSOpts = maps:get(tls_opts, Destination, []),
TLSTimeout = maps:get(tls_handshake_timeout, Destination, infinity),