diff options
Diffstat (limited to 'src/cowboy_ssl_transport.erl')
-rw-r--r-- | src/cowboy_ssl_transport.erl | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/src/cowboy_ssl_transport.erl b/src/cowboy_ssl_transport.erl index bf8b1fb..ccd8e5a 100644 --- a/src/cowboy_ssl_transport.erl +++ b/src/cowboy_ssl_transport.erl @@ -58,8 +58,7 @@ messages() -> {ssl, ssl_closed, ssl_error}. %% </dl> %% %% @see ssl:listen/2 -%% @todo The password option shouldn't be mandatory. --spec listen([{port, inet:ip_port()} | {certfile, string()} +-spec listen([{port, inet:port_number()} | {certfile, string()} | {keyfile, string()} | {password, string()} | {cacertfile, string()} | {ip, inet:ip_address()}]) -> {ok, ssl:sslsocket()} | {error, atom()}. @@ -68,21 +67,30 @@ listen(Opts) -> {port, Port} = lists:keyfind(port, 1, Opts), Backlog = proplists:get_value(backlog, Opts, 1024), {certfile, CertFile} = lists:keyfind(certfile, 1, Opts), - {keyfile, KeyFile} = lists:keyfind(keyfile, 1, Opts), - {password, Password} = lists:keyfind(password, 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}, {backlog, Backlog}, {packet, raw}, {reuseaddr, true}, - {certfile, CertFile}, {keyfile, KeyFile}, {password, Password}], + {certfile, CertFile}], ListenOpts1 = case lists:keyfind(ip, 1, Opts) of false -> ListenOpts0; Ip -> [Ip|ListenOpts0] end, - ListenOpts = + ListenOpts2 = case lists:keyfind(cacertfile, 1, Opts) of false -> ListenOpts1; CACertFile -> [CACertFile|ListenOpts1] end, + ListenOpts = ListenOpts2 ++ KeyFileOpts ++ PasswordOpts, ssl:listen(Port, ListenOpts). %% @doc Accept an incoming connection on a listen socket. @@ -131,7 +139,7 @@ controlling_process(Socket, Pid) -> %% @doc Return the address and port for the other end of a connection. %% @see ssl:peername/1 -spec peername(ssl:sslsocket()) - -> {ok, {inet:ip_address(), inet:ip_port()}} | {error, atom()}. + -> {ok, {inet:ip_address(), inet:port_number()}} | {error, atom()}. peername(Socket) -> ssl:peername(Socket). |