aboutsummaryrefslogtreecommitdiffstats
path: root/src/cowboy_tls.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/cowboy_tls.erl')
-rw-r--r--src/cowboy_tls.erl18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/cowboy_tls.erl b/src/cowboy_tls.erl
index c049ecb..60ab2ed 100644
--- a/src/cowboy_tls.erl
+++ b/src/cowboy_tls.erl
@@ -1,4 +1,4 @@
-%% Copyright (c) 2015-2017, Loïc Hoguin <[email protected]>
+%% Copyright (c) 2015-2024, Loïc Hoguin <[email protected]>
%%
%% Permission to use, copy, modify, and/or distribute this software for any
%% purpose with or without fee is hereby granted, provided that the above
@@ -33,13 +33,7 @@ start_link(Ref, Transport, Opts) ->
-spec connection_process(pid(), ranch:ref(), module(), cowboy:opts()) -> ok.
connection_process(Parent, Ref, Transport, Opts) ->
- ProxyInfo = case maps:get(proxy_header, Opts, false) of
- true ->
- {ok, ProxyInfo0} = ranch:recv_proxy_header(Ref, 1000),
- ProxyInfo0;
- false ->
- undefined
- end,
+ ProxyInfo = get_proxy_info(Ref, Opts),
{ok, Socket} = ranch:handshake(Ref),
case ssl:negotiated_protocol(Socket) of
{ok, <<"h2">>} ->
@@ -54,3 +48,11 @@ init(Parent, Ref, Socket, Transport, ProxyInfo, Opts, Protocol) ->
supervisor -> process_flag(trap_exit, true)
end,
Protocol:init(Parent, Ref, Socket, Transport, ProxyInfo, Opts).
+
+get_proxy_info(Ref, #{proxy_header := true}) ->
+ case ranch:recv_proxy_header(Ref, 1000) of
+ {ok, ProxyInfo} -> ProxyInfo;
+ {error, closed} -> exit({shutdown, closed})
+ end;
+get_proxy_info(_, _) ->
+ undefined.