From e2d899ad6e0f0ad6117c31c89151ab8e6adacf83 Mon Sep 17 00:00:00 2001 From: Shawn <506895667@qq.com> Date: Thu, 30 Dec 2021 15:30:41 +0800 Subject: [PATCH] fix(bridge): HTTP reqeust crash if using GET an DELETE method --- apps/emqx_connector/src/emqx_connector_http.erl | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/apps/emqx_connector/src/emqx_connector_http.erl b/apps/emqx_connector/src/emqx_connector_http.erl index 509e293cf..8b366070d 100644 --- a/apps/emqx_connector/src/emqx_connector_http.erl +++ b/apps/emqx_connector/src/emqx_connector_http.erl @@ -201,7 +201,7 @@ on_query(InstId, {KeyOrNum, Method, Request, Timeout}, AfterQuery, #{pool_name := PoolName, base_path := BasePath} = State) -> ?TRACE("QUERY", "http_connector_received", #{request => Request, connector => InstId, state => State}), - NRequest = update_path(BasePath, Request), + NRequest = formalize_request(Method, BasePath, Request), case Result = ehttpc:request(case KeyOrNum of undefined -> PoolName; _ -> {PoolName, KeyOrNum} @@ -310,10 +310,14 @@ check_ssl_opts(URLFrom, Conf) -> {_, _} -> false end. -update_path(BasePath, {Path, Headers}) -> - {filename:join(BasePath, Path), Headers}; -update_path(BasePath, {Path, Headers, Body}) -> - {filename:join(BasePath, Path), Headers, Body}. +formalize_request(Method, BasePath, {Path, Headers, _Body}) + when Method =:= get; Method =:= delete -> + formalize_request(Method, BasePath, {Path, Headers}); +formalize_request(_Method, BasePath, {Path, Headers, Body}) -> + {filename:join(BasePath, Path), Headers, Body}; + +formalize_request(_Method, BasePath, {Path, Headers}) -> + {filename:join(BasePath, Path), Headers}. bin(Bin) when is_binary(Bin) -> Bin;