From 0ecaa80fb899d83e6122e78dc27b21d31ad0a8c8 Mon Sep 17 00:00:00 2001 From: tigercl Date: Thu, 17 Jun 2021 16:12:08 +0800 Subject: [PATCH] fix(query string): support query string in path (#4981) --- apps/emqx_auth_http/src/emqx_auth_http.app.src | 2 +- apps/emqx_auth_http/src/emqx_auth_http.appup.src | 16 ++++++++++++++++ apps/emqx_auth_http/src/emqx_auth_http_app.erl | 13 ++++++++----- apps/emqx_web_hook/src/emqx_web_hook.app.src | 2 +- apps/emqx_web_hook/src/emqx_web_hook.appup.src | 12 +++++++----- apps/emqx_web_hook/src/emqx_web_hook_actions.erl | 14 +++++++++++--- apps/emqx_web_hook/src/emqx_web_hook_app.erl | 13 ++++++++----- 7 files changed, 52 insertions(+), 20 deletions(-) create mode 100644 apps/emqx_auth_http/src/emqx_auth_http.appup.src diff --git a/apps/emqx_auth_http/src/emqx_auth_http.app.src b/apps/emqx_auth_http/src/emqx_auth_http.app.src index b2c3221e6..305487171 100644 --- a/apps/emqx_auth_http/src/emqx_auth_http.app.src +++ b/apps/emqx_auth_http/src/emqx_auth_http.app.src @@ -1,6 +1,6 @@ {application, emqx_auth_http, [{description, "EMQ X Authentication/ACL with HTTP API"}, - {vsn, "4.3.0"}, % strict semver, bump manually! + {vsn, "4.3.1"}, % strict semver, bump manually! {modules, []}, {registered, [emqx_auth_http_sup]}, {applications, [kernel,stdlib,ehttpc]}, diff --git a/apps/emqx_auth_http/src/emqx_auth_http.appup.src b/apps/emqx_auth_http/src/emqx_auth_http.appup.src new file mode 100644 index 000000000..620194064 --- /dev/null +++ b/apps/emqx_auth_http/src/emqx_auth_http.appup.src @@ -0,0 +1,16 @@ +%% -*-: erlang -*- + +{VSN, + [ + {"4.3.0", [ + {restart_application, emqx_auth_http} + ]}, + {<<".*">>, []} + ], + [ + {"4.3.0", [ + {restart_application, emqx_auth_http} + ]}, + {<<".*">>, []} + ] +}. diff --git a/apps/emqx_auth_http/src/emqx_auth_http_app.erl b/apps/emqx_auth_http/src/emqx_auth_http_app.erl index 7d4781f7c..51e376f6a 100644 --- a/apps/emqx_auth_http/src/emqx_auth_http_app.erl +++ b/apps/emqx_auth_http/src/emqx_auth_http_app.erl @@ -54,10 +54,9 @@ translate_env(EnvName) -> {ok, ConnectTimeout} = application:get_env(?APP, connect_timeout), URL = proplists:get_value(url, Req), {ok, #{host := Host, - path := Path0, port := Port, - scheme := Scheme}} = emqx_http_lib:uri_parse(URL), - Path = path(Path0), + scheme := Scheme} = URIMap} = emqx_http_lib:uri_parse(URL), + Path = path(URIMap), MoreOpts = case Scheme of http -> [{transport_opts, emqx_misc:ipv6_probe([])}]; @@ -151,8 +150,12 @@ ensure_content_type_header(Method, Headers) ensure_content_type_header(_Method, Headers) -> lists:keydelete("content-type", 1, Headers). -path("") -> +path(#{path := "", 'query' := Query}) -> + "?" ++ Query; +path(#{path := Path, 'query' := Query}) -> + Path ++ "?" ++ Query; +path(#{path := ""}) -> "/"; -path(Path) -> +path(#{path := Path}) -> Path. diff --git a/apps/emqx_web_hook/src/emqx_web_hook.app.src b/apps/emqx_web_hook/src/emqx_web_hook.app.src index 97624a900..e1cfda173 100644 --- a/apps/emqx_web_hook/src/emqx_web_hook.app.src +++ b/apps/emqx_web_hook/src/emqx_web_hook.app.src @@ -1,6 +1,6 @@ {application, emqx_web_hook, [{description, "EMQ X WebHook Plugin"}, - {vsn, "4.3.1"}, % strict semver, bump manually! + {vsn, "4.3.2"}, % strict semver, bump manually! {modules, []}, {registered, [emqx_web_hook_sup]}, {applications, [kernel,stdlib,ehttpc]}, diff --git a/apps/emqx_web_hook/src/emqx_web_hook.appup.src b/apps/emqx_web_hook/src/emqx_web_hook.appup.src index b92284b64..ae6e9e1ae 100644 --- a/apps/emqx_web_hook/src/emqx_web_hook.appup.src +++ b/apps/emqx_web_hook/src/emqx_web_hook.appup.src @@ -2,14 +2,16 @@ {VSN, [ - {"4.3.0", [ - {load_module, emqx_web_hook_actions, brutal_purge, soft_purge, []} - ]}, + {<<"4.3.[0-1]">>, [ + {restart_application, emqx_web_hook}, + {apply,{emqx_rule_engine,refresh_resource,[web_hook]}} + ]}, {<<".*">>, []} ], [ - {"4.3.0", [ - {load_module, emqx_web_hook_actions, brutal_purge, soft_purge, []} + {<<"4.3.[0-1]">>, [ + {restart_application, emqx_web_hook}, + {apply,{emqx_rule_engine,refresh_resource,[web_hook]}} ]}, {<<".*">>, []} ] diff --git a/apps/emqx_web_hook/src/emqx_web_hook_actions.erl b/apps/emqx_web_hook/src/emqx_web_hook_actions.erl index f8e4d8f08..8bb1c7de0 100644 --- a/apps/emqx_web_hook/src/emqx_web_hook_actions.erl +++ b/apps/emqx_web_hook/src/emqx_web_hook_actions.erl @@ -292,7 +292,7 @@ parse_action_params(Params = #{<<"url">> := URL}) -> Headers = headers(maps:get(<<"headers">>, Params, undefined)), NHeaders = ensure_content_type_header(Headers, Method), #{method => Method, - path => path(filename:join(CommonPath, maps:get(<<"path">>, Params, <<>>))), + path => merge_path(CommonPath, maps:get(<<"path">>, Params, <<>>)), headers => NHeaders, body => maps:get(<<"body">>, Params, <<>>), request_timeout => cuttlefish_duration:parse(str(maps:get(<<"request_timeout">>, Params, <<"5s">>))), @@ -306,8 +306,16 @@ ensure_content_type_header(Headers, Method) when Method =:= post orelse Method = ensure_content_type_header(Headers, _Method) -> lists:keydelete("content-type", 1, Headers). -path(<<>>) -> <<"/">>; -path(Path) -> Path. +merge_path(CommonPath, <<>>) -> + CommonPath; +merge_path(CommonPath, Path0) -> + case emqx_http_lib:uri_parse(Path0) of + {ok, #{path := Path1, 'query' := Query}} -> + Path2 = filename:join(CommonPath, Path1), + <>; + {ok, #{path := Path1}} -> + filename:join(CommonPath, Path1) + end. method(GET) when GET == <<"GET">>; GET == <<"get">> -> get; method(POST) when POST == <<"POST">>; POST == <<"post">> -> post; diff --git a/apps/emqx_web_hook/src/emqx_web_hook_app.erl b/apps/emqx_web_hook/src/emqx_web_hook_app.erl index 492af628d..580742c47 100644 --- a/apps/emqx_web_hook/src/emqx_web_hook_app.erl +++ b/apps/emqx_web_hook/src/emqx_web_hook_app.erl @@ -42,10 +42,9 @@ stop(_State) -> translate_env() -> {ok, URL} = application:get_env(?APP, url), {ok, #{host := Host, - path := Path0, port := Port, - scheme := Scheme}} = emqx_http_lib:uri_parse(URL), - Path = path(Path0), + scheme := Scheme} = URIMap} = emqx_http_lib:uri_parse(URL), + Path = path(URIMap), PoolSize = application:get_env(?APP, pool_size, 32), MoreOpts = case Scheme of http -> @@ -89,9 +88,13 @@ translate_env() -> NHeaders = set_content_type(Headers), application:set_env(?APP, headers, NHeaders). -path("") -> +path(#{path := "", 'query' := Query}) -> + "?" ++ Query; +path(#{path := Path, 'query' := Query}) -> + Path ++ "?" ++ Query; +path(#{path := ""}) -> "/"; -path(Path) -> +path(#{path := Path}) -> Path. set_content_type(Headers) ->