This commit is contained in:
JianBo He 2022-07-01 16:46:13 +08:00 committed by JimMoen
parent 52b77b570f
commit 83f5da8f9d
2 changed files with 12 additions and 7 deletions

View File

@ -85,11 +85,7 @@ authorize(
{ok, 204, _Headers} -> {ok, 204, _Headers} ->
{matched, allow}; {matched, allow};
{ok, 200, Headers, Body} -> {ok, 200, Headers, Body} ->
ContentType = proplists:get_value( ContentType = content_type(Headers),
<<"content-type">>,
Headers,
<<"application/json">>
),
case emqx_authz_utils:parse_http_resp_body(ContentType, Body) of case emqx_authz_utils:parse_http_resp_body(ContentType, Body) of
error -> error ->
?SLOG(error, #{ ?SLOG(error, #{
@ -222,6 +218,15 @@ serialize_body(<<"application/json">>, Body) ->
serialize_body(<<"application/x-www-form-urlencoded">>, Body) -> serialize_body(<<"application/x-www-form-urlencoded">>, Body) ->
query_string(Body). query_string(Body).
content_type(Headers) when is_list(Headers) ->
content_type(maps:from_list(Headers));
content_type(#{<<"content-type">> := Type}) ->
Type;
content_type(#{<<"Content-Type">> := Type}) ->
Type;
content_type(Headers) when is_map(Headers) ->
<<"application/json">>.
client_vars(Client, PubSub, Topic) -> client_vars(Client, PubSub, Topic) ->
Client#{ Client#{
action => PubSub, action => PubSub,

View File

@ -133,13 +133,13 @@ render_sql_params(ParamList, Values) ->
). ).
-spec parse_http_resp_body(binary(), binary()) -> allow | deny | ignore | error. -spec parse_http_resp_body(binary(), binary()) -> allow | deny | ignore | error.
parse_http_resp_body(<<"application/x-www-form-urlencoded">>, Body) -> parse_http_resp_body(<<"application/x-www-form-urlencoded", _/binary>>, Body) ->
try try
result(maps:from_list(cow_qs:parse_qs(Body))) result(maps:from_list(cow_qs:parse_qs(Body)))
catch catch
_:_ -> error _:_ -> error
end; end;
parse_http_resp_body(<<"application/json">>, Body) -> parse_http_resp_body(<<"application/json", _/binary>>, Body) ->
try try
result(emqx_json:decode(Body, [return_maps])) result(emqx_json:decode(Body, [return_maps]))
catch catch