diff --git a/apps/emqx/rebar.config b/apps/emqx/rebar.config index 31caa498d..3d016a461 100644 --- a/apps/emqx/rebar.config +++ b/apps/emqx/rebar.config @@ -17,7 +17,7 @@ , {esockd, {git, "https://github.com/emqx/esockd", {tag, "5.9.0"}}} , {ekka, {git, "https://github.com/emqx/ekka", {tag, "0.11.1"}}} , {gen_rpc, {git, "https://github.com/emqx/gen_rpc", {tag, "2.5.1"}}} - , {hocon, {git, "https://github.com/emqx/hocon.git", {tag, "0.22.1"}}} + , {hocon, {git, "https://github.com/emqx/hocon.git", {tag, "0.22.3"}}} , {pbkdf2, {git, "https://github.com/emqx/erlang-pbkdf2.git", {tag, "2.0.4"}}} , {recon, {git, "https://github.com/ferd/recon", {tag, "2.5.1"}}} , {snabbkaffe, {git, "https://github.com/kafka4beam/snabbkaffe.git", {tag, "0.16.0"}}} diff --git a/apps/emqx_authz/src/emqx_authz_http.erl b/apps/emqx_authz/src/emqx_authz_http.erl index 3721aef28..5ee0a6d94 100644 --- a/apps/emqx_authz/src/emqx_authz_http.erl +++ b/apps/emqx_authz/src/emqx_authz_http.erl @@ -124,14 +124,14 @@ generate_request( PubSub case Method of get -> NPath = append_query(Path, NBaseQuery ++ Body), - {NPath, maps:to_list(Headers)}; + {NPath, Headers}; _ -> NPath = append_query(Path, NBaseQuery), NBody = serialize_body( maps:get(<<"Accept">>, Headers, <<"application/json">>), Body ), - {NPath, maps:to_list(Headers), NBody} + {NPath, Headers, NBody} end. append_query(Path, []) -> diff --git a/apps/emqx_authz/src/emqx_authz_schema.erl b/apps/emqx_authz/src/emqx_authz_schema.erl index 752d656ba..d68d97cf3 100644 --- a/apps/emqx_authz/src/emqx_authz_schema.erl +++ b/apps/emqx_authz/src/emqx_authz_schema.erl @@ -33,6 +33,7 @@ ]). -import(emqx_schema, [mk_duration/2]). +-include_lib("hocon/include/hoconsc.hrl"). %%-------------------------------------------------------------------- %% Hocon Schema @@ -158,20 +159,20 @@ validations() -> , {check_headers, fun check_headers/1} ]. -headers(type) -> map(); +headers(type) -> list({binary(), binary()}); headers(converter) -> fun(Headers) -> - maps:merge(default_headers(), transform_header_name(Headers)) + maps:to_list(maps:merge(default_headers(), transform_header_name(Headers))) end; -headers(default) -> default_headers(); +headers(default) -> maps:to_list(default_headers()); headers(_) -> undefined. -headers_no_content_type(type) -> map(); +headers_no_content_type(type) -> list({binary(), binary()}); headers_no_content_type(converter) -> fun(Headers) -> - maps:merge(default_headers_no_content_type(), transform_header_name(Headers)) + maps:to_list(maps:merge(default_headers_no_content_type(), transform_header_name(Headers))) end; -headers_no_content_type(default) -> default_headers_no_content_type(); +headers_no_content_type(default) -> maps:to_list(default_headers_no_content_type()); headers_no_content_type(_) -> undefined. url(type) -> binary(); @@ -221,7 +222,7 @@ check_headers(Conf) check_headers(Conf) -> Method = to_bin(hocon_schema:get_value("config.method", Conf)), Headers = hocon_schema:get_value("config.headers", Conf), - Method =:= <<"post">> orelse (not maps:is_key(<<"content-type">>, Headers)). + Method =:= <<"post">> orelse (not lists:member(<<"content-type">>, Headers)). union_array(Item) when is_list(Item) -> hoconsc:array(hoconsc:union(Item)). diff --git a/apps/emqx_connector/src/emqx_connector_http.erl b/apps/emqx_connector/src/emqx_connector_http.erl index 8b366070d..42bfe85b1 100644 --- a/apps/emqx_connector/src/emqx_connector_http.erl +++ b/apps/emqx_connector/src/emqx_connector_http.erl @@ -262,11 +262,20 @@ preprocess_request(#{ , request_timeout => maps:get(request_timeout, Req, 30000) }. -preproc_headers(Headers) -> +preproc_headers(Headers) when is_map(Headers) -> maps:fold(fun(K, V, Acc) -> - Acc#{emqx_plugin_libs_rule:preproc_tmpl(bin(K)) => - emqx_plugin_libs_rule:preproc_tmpl(bin(V))} - end, #{}, Headers). + [{ + emqx_plugin_libs_rule:preproc_tmpl(bin(K)), + emqx_plugin_libs_rule:preproc_tmpl(bin(V)) + } | Acc] + end, [], Headers); +preproc_headers(Headers) when is_list(Headers) -> + lists:map(fun({K, V}) -> + { + emqx_plugin_libs_rule:preproc_tmpl(bin(K)), + emqx_plugin_libs_rule:preproc_tmpl(bin(V)) + } + end, Headers). process_request(#{ method := MethodTks, @@ -278,7 +287,7 @@ process_request(#{ Conf#{ method => make_method(emqx_plugin_libs_rule:proc_tmpl(MethodTks, Msg)) , path => emqx_plugin_libs_rule:proc_tmpl(PathTks, Msg) , body => process_request_body(BodyTks, Msg) - , headers => maps:to_list(proc_headers(HeadersTks, Msg)) + , headers => proc_headers(HeadersTks, Msg) , request_timeout => ReqTimeout }. @@ -288,10 +297,12 @@ process_request_body(BodyTks, Msg) -> emqx_plugin_libs_rule:proc_tmpl(BodyTks, Msg). proc_headers(HeaderTks, Msg) -> - maps:fold(fun(K, V, Acc) -> - Acc#{emqx_plugin_libs_rule:proc_tmpl(K, Msg) => - emqx_plugin_libs_rule:proc_tmpl(V, Msg)} - end, #{}, HeaderTks). + lists:map(fun({K, V}) -> + { + emqx_plugin_libs_rule:proc_tmpl(K, Msg), + emqx_plugin_libs_rule:proc_tmpl(V, Msg) + } + end, HeaderTks). make_method(M) when M == <<"POST">>; M == <<"post">> -> post; make_method(M) when M == <<"PUT">>; M == <<"put">> -> put; diff --git a/apps/emqx_dashboard/src/emqx_dashboard_swagger.erl b/apps/emqx_dashboard/src/emqx_dashboard_swagger.erl index be8b4d074..1fbdb9eca 100644 --- a/apps/emqx_dashboard/src/emqx_dashboard_swagger.erl +++ b/apps/emqx_dashboard/src/emqx_dashboard_swagger.erl @@ -436,6 +436,7 @@ typename_to_spec("timeout()", _Mod) -> #{<<"oneOf">> => [#{type => string, examp typename_to_spec("bytesize()", _Mod) -> #{type => string, example => <<"32MB">>}; typename_to_spec("wordsize()", _Mod) -> #{type => string, example => <<"1024KB">>}; typename_to_spec("map()", _Mod) -> #{type => object, example => #{}}; +typename_to_spec("{binary(), binary()}", _Mod) -> #{type => object, example => #{}}; typename_to_spec("comma_separated_list()", _Mod) -> #{type => string, example => <<"item1,item2">>}; typename_to_spec("comma_separated_atoms()", _Mod) -> diff --git a/rebar.config b/rebar.config index 61a3f4510..91a2aca1c 100644 --- a/rebar.config +++ b/rebar.config @@ -65,7 +65,7 @@ , {system_monitor, {git, "https://github.com/klarna-incubator/system_monitor", {tag, "2.2.0"}}} , {getopt, "1.0.2"} , {snabbkaffe, {git, "https://github.com/kafka4beam/snabbkaffe.git", {tag, "0.16.0"}}} - , {hocon, {git, "https://github.com/emqx/hocon.git", {tag, "0.22.1"}}} + , {hocon, {git, "https://github.com/emqx/hocon.git", {tag, "0.22.3"}}} , {emqx_http_lib, {git, "https://github.com/emqx/emqx_http_lib.git", {tag, "0.4.1"}}} , {esasl, {git, "https://github.com/emqx/esasl", {tag, "0.2.0"}}} , {jose, {git, "https://github.com/potatosalad/erlang-jose", {tag, "1.11.2"}}}