mirror of
https://github.com/processone/ejabberd
synced 2025-10-06 03:50:15 +02:00
Improve misc:uri_parse
This commit is contained in:
parent
c3d8c3d9c5
commit
54a1fcc5e8
3 changed files with 17 additions and 10 deletions
23
src/misc.erl
23
src/misc.erl
|
@ -56,23 +56,30 @@
|
||||||
|
|
||||||
-type distance_cache() :: #{{string(), string()} => non_neg_integer()}.
|
-type distance_cache() :: #{{string(), string()} => non_neg_integer()}.
|
||||||
|
|
||||||
|
-spec uri_parse(binary()|string()) -> {ok, string(), string(), number(), string(), string()} | {error, term()}.
|
||||||
-ifdef(USE_OLD_HTTP_URI).
|
-ifdef(USE_OLD_HTTP_URI).
|
||||||
uri_parse(URL) when is_binary(URL) ->
|
uri_parse(URL) when is_binary(URL) ->
|
||||||
uri_parse(binary_to_list(URL));
|
uri_parse(binary_to_list(URL));
|
||||||
uri_parse(URL) ->
|
uri_parse(URL) ->
|
||||||
{ok, {Scheme, _UserInfo, Host, Port, Path, _Query}} = http_uri:parse(URL),
|
case http_uri:parse(URL) of
|
||||||
{ok, Scheme, Host, Port, Path}.
|
{ok, {Scheme, _UserInfo, Host, Port, Path, Query}} ->
|
||||||
|
{ok, Scheme, Host, Port, Path, Query};
|
||||||
|
{error, _} = E ->
|
||||||
|
E
|
||||||
|
end.
|
||||||
-else.
|
-else.
|
||||||
uri_parse(URL) when is_binary(URL) ->
|
uri_parse(URL) when is_binary(URL) ->
|
||||||
uri_parse(binary_to_list(URL));
|
uri_parse(binary_to_list(URL));
|
||||||
uri_parse(URL) ->
|
uri_parse(URL) ->
|
||||||
case uri_string:parse(URL) of
|
case uri_string:parse(URL) of
|
||||||
#{scheme := Scheme, host := Host, port := Port, path := Path} ->
|
#{scheme := Scheme, host := Host, port := Port, path := Path} = M1 ->
|
||||||
{ok, Scheme, Host, Port, Path};
|
{ok, Scheme, Host, Port, Path, maps:get(query, M1, "")};
|
||||||
#{scheme := "https", host := Host, path := Path} ->
|
#{scheme := "https", host := Host, path := Path} = M2 ->
|
||||||
{ok, "https", Host, 443, Path};
|
{ok, "https", Host, 443, Path, maps:get(query, M2, "")};
|
||||||
#{scheme := "http", host := Host, path := Path} ->
|
#{scheme := "http", host := Host, path := Path} = M3 ->
|
||||||
{ok, "http", Host, 80, Path}
|
{ok, "http", Host, 80, Path, maps:get(query, M3, "")};
|
||||||
|
{error, Atom, _} ->
|
||||||
|
{error, Atom}
|
||||||
end.
|
end.
|
||||||
-endif.
|
-endif.
|
||||||
|
|
||||||
|
|
|
@ -713,7 +713,7 @@ get_proc_name(ServerHost, ModuleName) ->
|
||||||
-spec get_proc_name(binary(), atom(), binary()) -> atom().
|
-spec get_proc_name(binary(), atom(), binary()) -> atom().
|
||||||
get_proc_name(ServerHost, ModuleName, PutURL) ->
|
get_proc_name(ServerHost, ModuleName, PutURL) ->
|
||||||
%% Once we depend on OTP >= 20.0, we can use binaries with http_uri.
|
%% Once we depend on OTP >= 20.0, we can use binaries with http_uri.
|
||||||
{ok, _Scheme, Host0, _Port, Path0} =
|
{ok, _Scheme, Host0, _Port, Path0, _Query} =
|
||||||
misc:uri_parse(expand_host(PutURL, ServerHost)),
|
misc:uri_parse(expand_host(PutURL, ServerHost)),
|
||||||
Host = jid:nameprep(iolist_to_binary(Host0)),
|
Host = jid:nameprep(iolist_to_binary(Host0)),
|
||||||
Path = str:strip(iolist_to_binary(Path0), right, $/),
|
Path = str:strip(iolist_to_binary(Path0), right, $/),
|
||||||
|
|
|
@ -357,7 +357,7 @@ mod_opt_type(via) ->
|
||||||
(econf:and_then(
|
(econf:and_then(
|
||||||
econf:url([tls, tcp, udp]),
|
econf:url([tls, tcp, udp]),
|
||||||
fun(URI) ->
|
fun(URI) ->
|
||||||
{ok, Type, Host, Port, _} =
|
{ok, Type, Host, Port, _, _} =
|
||||||
misc:uri_parse(URI),
|
misc:uri_parse(URI),
|
||||||
{Type, {unicode:characters_to_binary(Host), Port}}
|
{Type, {unicode:characters_to_binary(Host), Port}}
|
||||||
end))(U)
|
end))(U)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue