aboutsummaryrefslogtreecommitdiff
path: root/src/misc.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/misc.erl')
-rw-r--r--src/misc.erl23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/misc.erl b/src/misc.erl
index b502971a0..0733ef298 100644
--- a/src/misc.erl
+++ b/src/misc.erl
@@ -56,23 +56,30 @@
-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).
uri_parse(URL) when is_binary(URL) ->
uri_parse(binary_to_list(URL));
uri_parse(URL) ->
- {ok, {Scheme, _UserInfo, Host, Port, Path, _Query}} = http_uri:parse(URL),
- {ok, Scheme, Host, Port, Path}.
+ case http_uri:parse(URL) of
+ {ok, {Scheme, _UserInfo, Host, Port, Path, Query}} ->
+ {ok, Scheme, Host, Port, Path, Query};
+ {error, _} = E ->
+ E
+ end.
-else.
uri_parse(URL) when is_binary(URL) ->
uri_parse(binary_to_list(URL));
uri_parse(URL) ->
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}
+ #{scheme := Scheme, host := Host, port := Port, path := Path} = M1 ->
+ {ok, Scheme, Host, Port, Path, maps:get(query, M1, "")};
+ #{scheme := "https", host := Host, path := Path} = M2 ->
+ {ok, "https", Host, 443, Path, maps:get(query, M2, "")};
+ #{scheme := "http", host := Host, path := Path} = M3 ->
+ {ok, "http", Host, 80, Path, maps:get(query, M3, "")};
+ {error, Atom, _} ->
+ {error, Atom}
end.
-endif.