fix(bridge): HTTP reqeust crash if using GET an DELETE method

This commit is contained in:
Shawn 2021-12-30 15:30:41 +08:00
parent 9d733c2ec5
commit e2d899ad6e
1 changed files with 9 additions and 5 deletions

View File

@ -201,7 +201,7 @@ on_query(InstId, {KeyOrNum, Method, Request, Timeout}, AfterQuery,
#{pool_name := PoolName, base_path := BasePath} = State) -> #{pool_name := PoolName, base_path := BasePath} = State) ->
?TRACE("QUERY", "http_connector_received", ?TRACE("QUERY", "http_connector_received",
#{request => Request, connector => InstId, state => State}), #{request => Request, connector => InstId, state => State}),
NRequest = update_path(BasePath, Request), NRequest = formalize_request(Method, BasePath, Request),
case Result = ehttpc:request(case KeyOrNum of case Result = ehttpc:request(case KeyOrNum of
undefined -> PoolName; undefined -> PoolName;
_ -> {PoolName, KeyOrNum} _ -> {PoolName, KeyOrNum}
@ -310,10 +310,14 @@ check_ssl_opts(URLFrom, Conf) ->
{_, _} -> false {_, _} -> false
end. end.
update_path(BasePath, {Path, Headers}) -> formalize_request(Method, BasePath, {Path, Headers, _Body})
{filename:join(BasePath, Path), Headers}; when Method =:= get; Method =:= delete ->
update_path(BasePath, {Path, Headers, Body}) -> formalize_request(Method, BasePath, {Path, Headers});
{filename:join(BasePath, Path), Headers, Body}. 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(Bin) when is_binary(Bin) ->
Bin; Bin;