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

This commit is contained in:
tigercl 2021-06-17 16:12:08 +08:00 committed by GitHub
parent bdd9154001
commit 0ecaa80fb8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 52 additions and 20 deletions

View File

@ -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]},

View File

@ -0,0 +1,16 @@
%% -*-: erlang -*-
{VSN,
[
{"4.3.0", [
{restart_application, emqx_auth_http}
]},
{<<".*">>, []}
],
[
{"4.3.0", [
{restart_application, emqx_auth_http}
]},
{<<".*">>, []}
]
}.

View File

@ -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), scheme := Scheme} = URIMap} = emqx_http_lib:uri_parse(URL),
Path = path(Path0), 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.

View File

@ -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]},

View File

@ -2,14 +2,16 @@
{VSN, {VSN,
[ [
{"4.3.0", [ {<<"4.3.[0-1]">>, [
{load_module, emqx_web_hook_actions, brutal_purge, soft_purge, []} {restart_application, emqx_web_hook},
{apply,{emqx_rule_engine,refresh_resource,[web_hook]}}
]}, ]},
{<<".*">>, []} {<<".*">>, []}
], ],
[ [
{"4.3.0", [ {<<"4.3.[0-1]">>, [
{load_module, emqx_web_hook_actions, brutal_purge, soft_purge, []} {restart_application, emqx_web_hook},
{apply,{emqx_rule_engine,refresh_resource,[web_hook]}}
]}, ]},
{<<".*">>, []} {<<".*">>, []}
] ]

View File

@ -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(<<>>) -> <<"/">>; merge_path(CommonPath, <<>>) ->
path(Path) -> Path. 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;

View File

@ -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), scheme := Scheme} = URIMap} = emqx_http_lib:uri_parse(URL),
Path = path(Path0), 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) ->