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 4d3740a8e..48d123b70 100644 --- a/apps/emqx_authn/src/simple_authn/emqx_authn_http.erl +++ b/apps/emqx_authn/src/simple_authn/emqx_authn_http.erl @@ -113,15 +113,17 @@ create(ChainID, AuthenticatorName, request_timeout := RequestTimeout} = Config) -> #{path := Path, query := Query} = URIMap = parse_url(URL), - BaseURL = generate_base_url(URIMap), State = #{method => Method, path => Path, base_query => cow_qs:parse_qs(list_to_binary(Query)), - headers => maps:to_list(Headers), - form_data => FormData, + headers => normalize_headers(Headers), + form_data => maps:to_list(FormData), request_timeout => RequestTimeout}, ResourceID = <>, - case emqx_resource:create_local(ResourceID, emqx_connector_http, Config#{base_url => BaseURL}) of + case emqx_resource:create_local(ResourceID, + emqx_connector_http, + Config#{base_url => maps:remove(query, URIMap), + pool_type => random}) of {ok, _} -> {ok, State#{resource_id => ResourceID}}; {error, already_created} -> @@ -214,10 +216,8 @@ parse_url(URL) -> URIMap end. -generate_base_url(#{scheme := Scheme, - host := Host, - port := Port}) -> - iolist_to_binary(io_lib:format("~p://~s:~p", [Scheme, Host, Port])). +normalize_headers(Headers) -> + [{atom_to_binary(K), V} || {K, V} <- maps:to_list(Headers)]. generate_request(Credential, #{method := Method, path := Path, @@ -251,6 +251,8 @@ replace_placeholder(<<"${mqtt-username}">>, Credential) -> maps:get(username, Credential, undefined); replace_placeholder(<<"${mqtt-clientid}">>, Credential) -> maps:get(clientid, Credential, undefined); +replace_placeholder(<<"${mqtt-password}">>, Credential) -> + maps:get(password, Credential, undefined); replace_placeholder(<<"${ip-address}">>, Credential) -> maps:get(peerhost, Credential, undefined); replace_placeholder(<<"${cert-subject}">>, Credential) -> @@ -274,9 +276,9 @@ qs([], Acc) -> qs([{K, V} | More], Acc) -> qs(More, [["&", emqx_http_lib:uri_encode(K), "=", emqx_http_lib:uri_encode(V)] | Acc]). -serialize_body('application/json', FormData) -> +serialize_body(<<"application/json">>, FormData) -> emqx_json:encode(FormData); -serialize_body('application/x-www-form-urlencoded', FormData) -> +serialize_body(<<"application/x-www-form-urlencoded">>, FormData) -> qs(FormData). safely_parse_body(ContentType, Body) -> diff --git a/apps/emqx_connector/src/emqx_connector_http.erl b/apps/emqx_connector/src/emqx_connector_http.erl index d6d30eb76..30480eb35 100644 --- a/apps/emqx_connector/src/emqx_connector_http.erl +++ b/apps/emqx_connector/src/emqx_connector_http.erl @@ -147,7 +147,7 @@ on_start(InstId, #{base_url := #{scheme := Scheme, , {pool_type, PoolType} , {pool_size, PoolSize} , {transport, Transport} - , {transport, NTransportOpts}], + , {transport_opts, NTransportOpts}], PoolName = emqx_plugin_libs_pool:pool_name(InstId), {ok, _} = ehttpc_sup:start_pool(PoolName, PoolOpts), {ok, #{pool_name => PoolName,