Преглед изворни кода

fix(auth-http): support content-type header env variable override

Zaiming Shi пре 4 година
родитељ
комит
f68a89c9ba

+ 1 - 1
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

+ 1 - 4
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;