diff options
author | Loïc Hoguin <[email protected]> | 2020-08-19 17:24:27 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2020-09-21 15:51:57 +0200 |
commit | ca68d184abbf7bd1030b2f2035cc66c13d08dd5d (patch) | |
tree | 77a5800cbfc3da76e7863e1bbb51d83442bddf50 /src/gun_tls_proxy.erl | |
parent | a1729d5584364412f72d0d6337447da653da865b (diff) | |
download | gun-ca68d184abbf7bd1030b2f2035cc66c13d08dd5d.tar.gz gun-ca68d184abbf7bd1030b2f2035cc66c13d08dd5d.tar.bz2 gun-ca68d184abbf7bd1030b2f2035cc66c13d08dd5d.zip |
First working HTTPS over secure HTTP/2
Has a timer:sleep/1 though because there is currently no way
to wait for the TLS handshake to complete.
Diffstat (limited to 'src/gun_tls_proxy.erl')
-rw-r--r-- | src/gun_tls_proxy.erl | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/gun_tls_proxy.erl b/src/gun_tls_proxy.erl index 2b08088..35e83b1 100644 --- a/src/gun_tls_proxy.erl +++ b/src/gun_tls_proxy.erl @@ -95,6 +95,7 @@ extra :: any() }). +-define(DEBUG_PROXY, 1). -ifdef(DEBUG_PROXY). -define(DEBUG_LOG(Format, Args), io:format(user, "(~p) ~p:~p/~p:" ++ Format ++ "~n", @@ -114,6 +115,8 @@ start_link(Host, Port, Opts, Timeout, OutSocket, OutTransport, Extra) -> {ok, Pid} when is_port(OutSocket) -> ok = gen_tcp:controlling_process(OutSocket, Pid), {ok, Pid}; + {ok, Pid} when is_map(OutSocket) -> + {ok, Pid}; {ok, Pid} when not is_pid(OutSocket) -> ok = ssl:controlling_process(OutSocket, Pid), {ok, Pid}; @@ -262,6 +265,27 @@ connected({call, From}, Msg={send, Data}, State=#state{proxy_socket=Socket}) -> ?DEBUG_LOG("spawned ~0p", [SpawnedPid]), keep_state_and_data; %% Messages from the proxy socket. +%% +%% When the out_socket is a #{stream_ref := _} map we know that processing +%% of the data isn't yet complete. We wrap the message in a handle_continue +%% tuple and provide the StreamRef for further processing. +connected(info, Msg={ssl, Socket, Data}, State=#state{owner_pid=OwnerPid, proxy_socket=Socket, + out_socket=#{stream_ref := StreamRef}}) -> + ?DEBUG_LOG("msg ~0p state ~0p", [Msg, State]), + OwnerPid ! {handle_continue, StreamRef, {tls_proxy, self(), Data}}, + keep_state_and_data; +connected(info, Msg={ssl_closed, Socket}, State=#state{owner_pid=OwnerPid, proxy_socket=Socket, + out_socket=#{stream_ref := StreamRef}}) -> + ?DEBUG_LOG("msg ~0p state ~0p", [Msg, State]), + OwnerPid ! {handle_continue, StreamRef, {tls_proxy_closed, self()}}, + keep_state_and_data; +connected(info, Msg={ssl_error, Socket, Reason}, State=#state{owner_pid=OwnerPid, proxy_socket=Socket, + out_socket=#{stream_ref := StreamRef}}) -> + ?DEBUG_LOG("msg ~0p state ~0p", [Msg, State]), + OwnerPid ! {handle_continue, StreamRef, {tls_proxy_error, self(), Reason}}, + keep_state_and_data; +%% When the out_socket is anything else then the data is sent like normal +%% socket data. It does not need to be handled specially. connected(info, Msg={ssl, Socket, Data}, State=#state{owner_pid=OwnerPid, proxy_socket=Socket}) -> ?DEBUG_LOG("msg ~0p state ~0p", [Msg, State]), OwnerPid ! {tls_proxy, self(), Data}, |