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

This commit is contained in:
Zaiming Shi 2021-05-06 16:09:13 +02:00 committed by turtleDeng
parent 05c5378265
commit f68a89c9ba
2 changed files with 2 additions and 5 deletions

View File

@ -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

View File

@ -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;