From 3146cdda924e61e45c0f2346dfcbb98effed09e1 Mon Sep 17 00:00:00 2001 From: HeeeJianBo Date: Sun, 28 Jan 2018 14:25:41 +0800 Subject: [PATCH] Fix #1473 for supporting special chars in URL path --- src/emqttd_http.erl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/emqttd_http.erl b/src/emqttd_http.erl index 2b484038b..c229f4de2 100644 --- a/src/emqttd_http.erl +++ b/src/emqttd_http.erl @@ -45,7 +45,7 @@ http_api() -> %% Handle HTTP Request %%-------------------------------------------------------------------- handle_request(Req, State) -> - Path = Req:get(path), + {Path, _, _} = mochiweb_util:urlsplit_path(Req:get(raw_path)), case Path of "/status" -> handle_request("/status", Req, Req:get(method)); @@ -58,7 +58,7 @@ handle_request(Req, State) -> end. inner_handle_request(Req, State) -> - Path = Req:get(path), + {Path, _, _} = mochiweb_util:urlsplit_path(Req:get(raw_path)), case Path of "/api/v2/auth" -> handle_request(Path, Req, State); _ -> if_authorized(Req, fun() -> handle_request(Path, Req, State) end) @@ -95,7 +95,8 @@ dispatcher(APIs) -> case {check_params(Params, FilterArgs), check_params_type(Params, FilterArgs)} of {true, true} -> - {match, [MatchList]} = re:run(Url, Regexp, [global, {capture, all_but_first, list}]), + {match, [MatchList0]} = re:run(Url, Regexp, [global, {capture, all_but_first, list}]), + MatchList = lists:map(fun mochiweb_util:unquote/1, MatchList0), Args = lists:append([[Method, Params], MatchList]), lager:debug("Mod:~p, Fun:~p, Args:~p", [emqttd_rest_api, Function, Args]), case catch apply(emqttd_rest_api, Function, Args) of