Przeglądaj źródła

fix(query string): support query string in path (#4981)

tigercl 4 lat temu
rodzic
commit
bcedd7fe9e

+ 1 - 1
apps/emqx_auth_http/src/emqx_auth_http.app.src

@@ -1,6 +1,6 @@
 {application, emqx_auth_http,
 {application, emqx_auth_http,
  [{description, "EMQ X Authentication/ACL with HTTP API"},
  [{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, []},
   {modules, []},
   {registered, [emqx_auth_http_sup]},
   {registered, [emqx_auth_http_sup]},
   {applications, [kernel,stdlib,ehttpc]},
   {applications, [kernel,stdlib,ehttpc]},

+ 16 - 0
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}
+    ]},
+    {<<".*">>, []}
+  ]
+}.

+ 8 - 5
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),
             {ok, ConnectTimeout} = application:get_env(?APP, connect_timeout),
             URL = proplists:get_value(url, Req),
             URL = proplists:get_value(url, Req),
             {ok, #{host := Host,
             {ok, #{host := Host,
-                   path := Path0,
                    port := Port,
                    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
             MoreOpts = case Scheme of
                         http ->
                         http ->
                             [{transport_opts, emqx_misc:ipv6_probe([])}];
                             [{transport_opts, emqx_misc:ipv6_probe([])}];
@@ -151,8 +150,12 @@ ensure_content_type_header(Method, Headers)
 ensure_content_type_header(_Method, Headers) ->
 ensure_content_type_header(_Method, Headers) ->
     lists:keydelete("content-type", 1, 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.
     Path.
 
 

+ 1 - 1
apps/emqx_web_hook/src/emqx_web_hook.app.src

@@ -1,6 +1,6 @@
 {application, emqx_web_hook,
 {application, emqx_web_hook,
  [{description, "EMQ X WebHook Plugin"},
  [{description, "EMQ X WebHook Plugin"},
-  {vsn, "4.3.1"}, % strict semver, bump manually!
+  {vsn, "4.3.2"}, % strict semver, bump manually!
   {modules, []},
   {modules, []},
   {registered, [emqx_web_hook_sup]},
   {registered, [emqx_web_hook_sup]},
   {applications, [kernel,stdlib,ehttpc]},
   {applications, [kernel,stdlib,ehttpc]},

+ 7 - 5
apps/emqx_web_hook/src/emqx_web_hook.appup.src

@@ -2,14 +2,16 @@
 
 
 {VSN,
 {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]}}
     ]},
     ]},
     {<<".*">>, []}
     {<<".*">>, []}
   ]
   ]

+ 11 - 3
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)),
         Headers = headers(maps:get(<<"headers">>, Params, undefined)),
         NHeaders = ensure_content_type_header(Headers, Method),
         NHeaders = ensure_content_type_header(Headers, Method),
         #{method => Method,
         #{method => Method,
-          path => path(filename:join(CommonPath, maps:get(<<"path">>, Params, <<>>))),
+          path => merge_path(CommonPath, maps:get(<<"path">>, Params, <<>>)),
           headers => NHeaders,
           headers => NHeaders,
           body => maps:get(<<"body">>, Params, <<>>),
           body => maps:get(<<"body">>, Params, <<>>),
           request_timeout => cuttlefish_duration:parse(str(maps:get(<<"request_timeout">>, Params, <<"5s">>))),
           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) ->
 ensure_content_type_header(Headers, _Method) ->
     lists:keydelete("content-type", 1, Headers).
     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),
+            <<Path2/binary, "?", Query/binary>>;
+        {ok, #{path := Path1}} ->
+            filename:join(CommonPath, Path1)
+    end.
 
 
 method(GET) when GET == <<"GET">>; GET == <<"get">> -> get;
 method(GET) when GET == <<"GET">>; GET == <<"get">> -> get;
 method(POST) when POST == <<"POST">>; POST == <<"post">> -> post;
 method(POST) when POST == <<"POST">>; POST == <<"post">> -> post;

+ 8 - 5
apps/emqx_web_hook/src/emqx_web_hook_app.erl

@@ -42,10 +42,9 @@ stop(_State) ->
 translate_env() ->
 translate_env() ->
     {ok, URL} = application:get_env(?APP, url),
     {ok, URL} = application:get_env(?APP, url),
     {ok, #{host := Host,
     {ok, #{host := Host,
-           path := Path0,
            port := Port,
            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),
     PoolSize = application:get_env(?APP, pool_size, 32),
     MoreOpts = case Scheme of
     MoreOpts = case Scheme of
                    http ->
                    http ->
@@ -89,9 +88,13 @@ translate_env() ->
     NHeaders = set_content_type(Headers),
     NHeaders = set_content_type(Headers),
     application:set_env(?APP, headers, NHeaders).
     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.
     Path.
 
 
 set_content_type(Headers) ->
 set_content_type(Headers) ->