fix: make sure authz headers is binary.
This commit is contained in:
parent
4b4403354d
commit
303707d69d
|
@ -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, []) ->
|
||||
|
|
|
@ -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)).
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) ->
|
||||
|
|
Loading…
Reference in New Issue