From 1452023c937b7787418c037a67c5b6c6274d65c4 Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Sun, 12 May 2019 11:57:17 +0200 Subject: [PATCH] mod_http_upload: Case-insensitive host comparison Perform a case-insensitive lookup of the host name specified by the HTTP client. Fixes #2827. --- src/mod_http_upload.erl | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/mod_http_upload.erl b/src/mod_http_upload.erl index b3600e709..c1013fe77 100644 --- a/src/mod_http_upload.erl +++ b/src/mod_http_upload.erl @@ -508,9 +508,12 @@ process(_LocalPath, #request{method = Method, host = Host, ip = IP}) -> -spec get_proc_name(binary(), atom()) -> atom(). get_proc_name(ServerHost, ModuleName) -> PutURL = gen_mod:get_module_opt(ServerHost, ?MODULE, put_url), - {ok, {_Scheme, _UserInfo, Host, _Port, Path, _Query}} = + %% Once we depend on OTP >= 20.0, we can use binaries with http_uri. + {ok, {_Scheme, _UserInfo, Host0, _Port, Path0, _Query}} = http_uri:parse(binary_to_list(expand_host(PutURL, ServerHost))), - ProcPrefix = list_to_binary(string:strip(Host ++ Path, right, $/)), + Host = jid:nameprep(iolist_to_binary(Host0)), + Path = str:strip(iolist_to_binary(Path0), right, $/), + ProcPrefix = <>, gen_mod:get_module_proc(ProcPrefix, ModuleName). -spec expand_home(binary()) -> binary(). @@ -762,7 +765,8 @@ iq_disco_info(Host, Lang, Name, AddInfo) -> %% HTTP request handling. -spec parse_http_request(#request{}) -> {atom(), slot()}. -parse_http_request(#request{host = Host, path = Path}) -> +parse_http_request(#request{host = Host0, path = Path}) -> + Host = jid:nameprep(Host0), PrefixLength = length(Path) - 3, {ProcURL, Slot} = if PrefixLength > 0 -> Prefix = lists:sublist(Path, PrefixLength),