Fix #1473 for supporting special chars in URL path

This commit is contained in:
HeeeJianBo 2018-01-28 14:25:41 +08:00
parent f70bf23440
commit 3146cdda92
1 changed files with 4 additions and 3 deletions

View File

@ -45,7 +45,7 @@ http_api() ->
%% Handle HTTP Request %% Handle HTTP Request
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
handle_request(Req, State) -> handle_request(Req, State) ->
Path = Req:get(path), {Path, _, _} = mochiweb_util:urlsplit_path(Req:get(raw_path)),
case Path of case Path of
"/status" -> "/status" ->
handle_request("/status", Req, Req:get(method)); handle_request("/status", Req, Req:get(method));
@ -58,7 +58,7 @@ handle_request(Req, State) ->
end. end.
inner_handle_request(Req, State) -> inner_handle_request(Req, State) ->
Path = Req:get(path), {Path, _, _} = mochiweb_util:urlsplit_path(Req:get(raw_path)),
case Path of case Path of
"/api/v2/auth" -> handle_request(Path, Req, State); "/api/v2/auth" -> handle_request(Path, Req, State);
_ -> if_authorized(Req, fun() -> handle_request(Path, Req, State) end) _ -> if_authorized(Req, fun() -> handle_request(Path, Req, State) end)
@ -95,7 +95,8 @@ dispatcher(APIs) ->
case {check_params(Params, FilterArgs), case {check_params(Params, FilterArgs),
check_params_type(Params, FilterArgs)} of check_params_type(Params, FilterArgs)} of
{true, true} -> {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]), Args = lists:append([[Method, Params], MatchList]),
lager:debug("Mod:~p, Fun:~p, Args:~p", [emqttd_rest_api, Function, Args]), lager:debug("Mod:~p, Fun:~p, Args:~p", [emqttd_rest_api, Function, Args]),
case catch apply(emqttd_rest_api, Function, Args) of case catch apply(emqttd_rest_api, Function, Args) of