mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-15 04:30:25 +00:00
Simplify the options filtering code in cowboy_ssl_transport
This commit is contained in:
parent
7e74582432
commit
98c58280f6
1 changed files with 8 additions and 21 deletions
|
@ -67,30 +67,17 @@ listen(Opts) ->
|
||||||
{port, Port} = lists:keyfind(port, 1, Opts),
|
{port, Port} = lists:keyfind(port, 1, Opts),
|
||||||
Backlog = proplists:get_value(backlog, Opts, 1024),
|
Backlog = proplists:get_value(backlog, Opts, 1024),
|
||||||
{certfile, CertFile} = lists:keyfind(certfile, 1, Opts),
|
{certfile, CertFile} = lists:keyfind(certfile, 1, Opts),
|
||||||
KeyFileOpts =
|
|
||||||
case lists:keyfind(keyfile, 1, Opts) of
|
|
||||||
false -> [];
|
|
||||||
KeyFile -> [KeyFile]
|
|
||||||
end,
|
|
||||||
PasswordOpts =
|
|
||||||
case lists:keyfind(password, 1, Opts) of
|
|
||||||
false -> [];
|
|
||||||
Password -> [Password]
|
|
||||||
end,
|
|
||||||
ListenOpts0 = [binary, {active, false},
|
ListenOpts0 = [binary, {active, false},
|
||||||
{backlog, Backlog}, {packet, raw}, {reuseaddr, true},
|
{backlog, Backlog}, {packet, raw}, {reuseaddr, true},
|
||||||
{certfile, CertFile}],
|
{certfile, CertFile}],
|
||||||
ListenOpts1 =
|
ListenOpts = lists:foldl(fun
|
||||||
case lists:keyfind(ip, 1, Opts) of
|
({ip, _} = Ip, Acc) -> [Ip | Acc];
|
||||||
false -> ListenOpts0;
|
({keyfile, _} = KeyFile, Acc) -> [KeyFile | Acc];
|
||||||
Ip -> [Ip|ListenOpts0]
|
({password, _} = Password, Acc) -> [Password | Acc];
|
||||||
end,
|
({cacertfile, _} = CACertFile, Acc) -> [CACertFile | Acc];
|
||||||
ListenOpts2 =
|
(_, Acc) -> Acc
|
||||||
case lists:keyfind(cacertfile, 1, Opts) of
|
end, ListenOpts0, Opts),
|
||||||
false -> ListenOpts1;
|
|
||||||
CACertFile -> [CACertFile|ListenOpts1]
|
|
||||||
end,
|
|
||||||
ListenOpts = ListenOpts2 ++ KeyFileOpts ++ PasswordOpts,
|
|
||||||
ssl:listen(Port, ListenOpts).
|
ssl:listen(Port, ListenOpts).
|
||||||
|
|
||||||
%% @doc Accept an incoming connection on a listen socket.
|
%% @doc Accept an incoming connection on a listen socket.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue