misc: Don't crash on URLs without port number

Let misc:uri_parse/1 return default HTTP(S) port number if the URL
doesn't specify a port number, analogous to the behavior when
USE_OLD_HTTP_URI is defined.
This commit is contained in:
Holger Weiss 2020-06-03 12:22:14 +02:00
parent 9ea51d3295
commit 945a5cd09c
1 changed files with 8 additions and 2 deletions

View File

@ -65,8 +65,14 @@ uri_parse(URL) ->
uri_parse(URL) when is_binary(URL) ->
uri_parse(binary_to_list(URL));
uri_parse(URL) ->
#{scheme:=Scheme,host:=Host,port:=Port,path:=Path} = uri_string:parse(URL),
{ok, Scheme, Host, Port, Path}.
case uri_string:parse(URL) of
#{scheme := Scheme, host := Host, port := Port, path := Path} ->
{ok, Scheme, Host, Port, Path};
#{scheme := "https", host := Host, path := Path} ->
{ok, "https", Host, 443, Path};
#{scheme := "http", host := Host, path := Path} ->
{ok, "http", Host, 80, Path}
end.
-endif.
-ifdef(USE_OLD_CRYPTO_HMAC).