fix(authz-http): fix https://github.com/emqx/emqx/pull/8377#discussion_r911743360
This commit is contained in:
parent
52b77b570f
commit
83f5da8f9d
|
@ -85,11 +85,7 @@ authorize(
|
|||
{ok, 204, _Headers} ->
|
||||
{matched, allow};
|
||||
{ok, 200, Headers, Body} ->
|
||||
ContentType = proplists:get_value(
|
||||
<<"content-type">>,
|
||||
Headers,
|
||||
<<"application/json">>
|
||||
),
|
||||
ContentType = content_type(Headers),
|
||||
case emqx_authz_utils:parse_http_resp_body(ContentType, Body) of
|
||||
error ->
|
||||
?SLOG(error, #{
|
||||
|
@ -222,6 +218,15 @@ serialize_body(<<"application/json">>, Body) ->
|
|||
serialize_body(<<"application/x-www-form-urlencoded">>, 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#{
|
||||
action => PubSub,
|
||||
|
|
|
@ -133,13 +133,13 @@ render_sql_params(ParamList, Values) ->
|
|||
).
|
||||
|
||||
-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
|
||||
result(maps:from_list(cow_qs:parse_qs(Body)))
|
||||
catch
|
||||
_:_ -> error
|
||||
end;
|
||||
parse_http_resp_body(<<"application/json">>, Body) ->
|
||||
parse_http_resp_body(<<"application/json", _/binary>>, Body) ->
|
||||
try
|
||||
result(emqx_json:decode(Body, [return_maps]))
|
||||
catch
|
||||
|
|
Loading…
Reference in New Issue