mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 20:30:23 +00:00
Accept only closed as error, crash otherwise.
This commit is contained in:
parent
148620ccf4
commit
286c10637a
2 changed files with 16 additions and 22 deletions
|
@ -33,10 +33,7 @@ start_link(Ref, Transport, Opts) ->
|
||||||
|
|
||||||
-spec connection_process(pid(), ranch:ref(), module(), cowboy:opts()) -> ok.
|
-spec connection_process(pid(), ranch:ref(), module(), cowboy:opts()) -> ok.
|
||||||
connection_process(Parent, Ref, Transport, Opts) ->
|
connection_process(Parent, Ref, Transport, Opts) ->
|
||||||
ProxyInfo = case maybe_proxy_info(Ref, Opts) of
|
ProxyInfo = get_proxy_info(Ref, Opts),
|
||||||
{ok, ProxyInfo0} -> ProxyInfo0;
|
|
||||||
Error -> exit({shutdown, Error})
|
|
||||||
end,
|
|
||||||
{ok, Socket} = ranch:handshake(Ref),
|
{ok, Socket} = ranch:handshake(Ref),
|
||||||
%% Use cowboy_http2 directly only when 'http' is missing.
|
%% Use cowboy_http2 directly only when 'http' is missing.
|
||||||
%% Otherwise switch to cowboy_http2 from cowboy_http.
|
%% Otherwise switch to cowboy_http2 from cowboy_http.
|
||||||
|
@ -56,10 +53,10 @@ init(Parent, Ref, Socket, Transport, ProxyInfo, Opts, Protocol) ->
|
||||||
end,
|
end,
|
||||||
Protocol:init(Parent, Ref, Socket, Transport, ProxyInfo, Opts).
|
Protocol:init(Parent, Ref, Socket, Transport, ProxyInfo, Opts).
|
||||||
|
|
||||||
maybe_proxy_info(Ref, Opts) ->
|
get_proxy_info(Ref, #{proxy_header := true}) ->
|
||||||
case maps:get(proxy_header, Opts, false) of
|
case ranch:recv_proxy_header(Ref, 1000) of
|
||||||
true ->
|
{ok, ProxyInfo} -> ProxyInfo;
|
||||||
ranch:recv_proxy_header(Ref, 1000);
|
{error, closed} -> exit({shutdown, closed})
|
||||||
false ->
|
end;
|
||||||
undefined
|
get_proxy_info(_, _) ->
|
||||||
end.
|
undefined.
|
||||||
|
|
|
@ -33,10 +33,7 @@ start_link(Ref, Transport, Opts) ->
|
||||||
|
|
||||||
-spec connection_process(pid(), ranch:ref(), module(), cowboy:opts()) -> ok.
|
-spec connection_process(pid(), ranch:ref(), module(), cowboy:opts()) -> ok.
|
||||||
connection_process(Parent, Ref, Transport, Opts) ->
|
connection_process(Parent, Ref, Transport, Opts) ->
|
||||||
ProxyInfo = case maybe_proxy_info(Ref, Opts) of
|
ProxyInfo = get_proxy_info(Ref, Opts),
|
||||||
{ok, ProxyInfo0} -> ProxyInfo0;
|
|
||||||
Error -> exit({shutdown, Error})
|
|
||||||
end,
|
|
||||||
{ok, Socket} = ranch:handshake(Ref),
|
{ok, Socket} = ranch:handshake(Ref),
|
||||||
case ssl:negotiated_protocol(Socket) of
|
case ssl:negotiated_protocol(Socket) of
|
||||||
{ok, <<"h2">>} ->
|
{ok, <<"h2">>} ->
|
||||||
|
@ -52,10 +49,10 @@ init(Parent, Ref, Socket, Transport, ProxyInfo, Opts, Protocol) ->
|
||||||
end,
|
end,
|
||||||
Protocol:init(Parent, Ref, Socket, Transport, ProxyInfo, Opts).
|
Protocol:init(Parent, Ref, Socket, Transport, ProxyInfo, Opts).
|
||||||
|
|
||||||
maybe_proxy_info(Ref, Opts) ->
|
get_proxy_info(Ref, #{proxy_header := true}) ->
|
||||||
case maps:get(proxy_header, Opts, false) of
|
case ranch:recv_proxy_header(Ref, 1000) of
|
||||||
true ->
|
{ok, ProxyInfo} -> ProxyInfo;
|
||||||
ranch:recv_proxy_header(Ref, 1000);
|
{error, closed} -> exit({shutdown, closed})
|
||||||
false ->
|
end;
|
||||||
undefined
|
get_proxy_info(_, _) ->
|
||||||
end.
|
undefined.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue