aboutsummaryrefslogtreecommitdiffstats
path: root/src/cowboy_clear.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/cowboy_clear.erl')
-rw-r--r--src/cowboy_clear.erl16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/cowboy_clear.erl b/src/cowboy_clear.erl
index 4f3a234..e4ca9da 100644
--- a/src/cowboy_clear.erl
+++ b/src/cowboy_clear.erl
@@ -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),
%% Use cowboy_http2 directly only when 'http' is missing.
%% Otherwise switch to cowboy_http2 from cowboy_http.
@@ -58,3 +52,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.