From 4744e4a5e4e87d9caa596f8b12a34ece897b61c4 Mon Sep 17 00:00:00 2001 From: JimMoen Date: Fri, 29 Apr 2022 19:43:13 +0800 Subject: [PATCH] fix(authn): make sure http headers are bin --- .../emqx_authn/src/simple_authn/emqx_authn_http.erl | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/apps/emqx_authn/src/simple_authn/emqx_authn_http.erl b/apps/emqx_authn/src/simple_authn/emqx_authn_http.erl index 9e25f5a7a..7bf591c72 100644 --- a/apps/emqx_authn/src/simple_authn/emqx_authn_http.erl +++ b/apps/emqx_authn/src/simple_authn/emqx_authn_http.erl @@ -172,7 +172,7 @@ create( State = #{ method => Method, path => Path, - headers => Headers, + headers => ensure_header_name_type(Headers), base_path_templete => emqx_authn_utils:parse_str(Path), base_query_template => emqx_authn_utils:parse_deep( cow_qs:parse_qs(to_bin(Query)) @@ -421,3 +421,14 @@ to_bin(L) when is_list(L) -> get_conf_val(Name, Conf) -> hocon_maps:get(?CONF_NS ++ "." ++ Name, Conf). + +ensure_header_name_type(Headers) -> + Fun = fun + (Key, _Val, Acc) when is_binary(Key) -> + Acc; + (Key, Val, Acc) when is_atom(Key) -> + Acc2 = maps:remove(Key, Acc), + BinKey = erlang:atom_to_binary(Key), + Acc2#{BinKey => Val} + end, + maps:fold(Fun, Headers, Headers).