From f68a89c9bafcafe38a2faeb49ab217868948be9c Mon Sep 17 00:00:00 2001 From: Zaiming Shi Date: Thu, 6 May 2021 16:09:13 +0200 Subject: [PATCH] fix(auth-http): support content-type header env variable override --- apps/emqx_auth_http/etc/emqx_auth_http.conf | 2 +- apps/emqx_auth_http/src/emqx_auth_http_app.erl | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/apps/emqx_auth_http/etc/emqx_auth_http.conf b/apps/emqx_auth_http/etc/emqx_auth_http.conf index 6c3cfbe8c..56a483681 100644 --- a/apps/emqx_auth_http/etc/emqx_auth_http.conf +++ b/apps/emqx_auth_http/etc/emqx_auth_http.conf @@ -18,7 +18,7 @@ auth.http.auth_req.method = post ## The possible values of the Content-Type header: application/x-www-form-urlencoded, application/json ## ## Examples: auth.http.auth_req.headers.accept = */* -auth.http.auth_req.headers.content-type = application/x-www-form-urlencoded +auth.http.auth_req.headers.content_type = application/x-www-form-urlencoded ## Parameters used to construct the request body or query string parameters ## When the request method is GET, these parameters will be converted into query string parameters diff --git a/apps/emqx_auth_http/src/emqx_auth_http_app.erl b/apps/emqx_auth_http/src/emqx_auth_http_app.erl index c5a7f2a77..7d4781f7c 100644 --- a/apps/emqx_auth_http/src/emqx_auth_http_app.erl +++ b/apps/emqx_auth_http/src/emqx_auth_http_app.erl @@ -96,7 +96,7 @@ translate_env(EnvName) -> {retry_timeout, 1000}] ++ MoreOpts, Method = proplists:get_value(method, Req), Headers = proplists:get_value(headers, Req), - NHeaders = ensure_content_type_header(Method, to_lower(Headers)), + NHeaders = ensure_content_type_header(Method, emqx_http_lib:normalise_headers(Headers)), NReq = lists:keydelete(headers, 1, Req), {ok, Timeout} = application:get_env(?APP, timeout), application:set_env(?APP, EnvName, [{path, Path}, @@ -145,9 +145,6 @@ unload_hooks() -> _ = ehttpc_sup:stop_pool('emqx_auth_http/acl_req'), ok. -to_lower(Headers) -> - [{string:to_lower(K), V} || {K, V} <- Headers]. - ensure_content_type_header(Method, Headers) when Method =:= post orelse Method =:= put -> Headers;