diff --git a/apps/ejabberd/src/mod_http_client.erl b/apps/ejabberd/src/mod_http_client.erl index 1ae529e35ff..b01855f17de 100644 --- a/apps/ejabberd/src/mod_http_client.erl +++ b/apps/ejabberd/src/mod_http_client.erl @@ -18,7 +18,7 @@ -behaviour(gen_mod). %% API --export([start_pool/3, stop_pool/2, get_pool/2, make_request/5]). +-export([start_pool/3, stop_pool/2, get_pool/2, get/3, post/4]). %% gen_mod callbacks -export([start/2, stop/1]). @@ -59,30 +59,15 @@ stop_pool(Host, Name) -> ets:delete(tab_name(Host), Name), ok. --spec make_request(pool(), binary(), binary(), list(), binary()) -> - {ok, {binary(), binary()}} | {error, any()}. -make_request(Pool, Path, Method, Header, Query) -> - #pool{path_prefix = PathPrefix, - name = Name, - host = Host, - pool_timeout = PoolTimeout, - request_timeout = RequestTimeout} = Pool, - FullPath = <>, - case catch poolboy:transaction( - pool_proc_name(Host, Name), - fun(WorkerPid) -> - fusco:request(WorkerPid, FullPath, Method, Header, Query, RequestTimeout) - end, - PoolTimeout) of - {'EXIT', {timeout, _}} -> - {error, pool_timeout}; - {ok, {{Code, _Reason}, _RespHeaders, RespBody, _, _}} -> - {ok, {Code, RespBody}}; - {error, timeout} -> - {error, request_timeout}; - {error, Reason} -> - {error, Reason} - end. +-spec get(pool(), binary(), list()) -> + {ok, {binary(), binary()}} | {error, any()}. +get(Pool, Path, Headers) -> + make_request(Pool, Path, <<"GET">>, Headers, <<>>). + +-spec post(pool(), binary(), list(), binary()) -> + {ok, {binary(), binary()}} | {error, any()}. +post(Pool, Path, Headers, Query) -> + make_request(Pool, Path, <<"POST">>, Headers, Query). %%------------------------------------------------------------------------------ %% gen_mod callbacks @@ -142,6 +127,29 @@ tab_name(Host) -> %% NOTE: The naming scheme for processes is reused for ETS table gen_mod:get_module_proc(Host, mod_http_client_pools). +make_request(Pool, Path, Method, Headers, Query) -> + #pool{path_prefix = PathPrefix, + name = Name, + host = Host, + pool_timeout = PoolTimeout, + request_timeout = RequestTimeout} = Pool, + FullPath = <>, + case catch poolboy:transaction( + pool_proc_name(Host, Name), + fun(WorkerPid) -> + fusco:request(WorkerPid, FullPath, Method, Headers, Query, RequestTimeout) + end, + PoolTimeout) of + {'EXIT', {timeout, _}} -> + {error, pool_timeout}; + {ok, {{Code, _Reason}, _RespHeaders, RespBody, _, _}} -> + {ok, {Code, RespBody}}; + {error, timeout} -> + {error, request_timeout}; + {error, Reason} -> + {error, Reason} + end. + start_supervisor(Host) -> Proc = gen_mod:get_module_proc(Host, ejabberd_mod_http_client_sup), ChildSpec = diff --git a/apps/ejabberd/src/mod_muc_room.erl b/apps/ejabberd/src/mod_muc_room.erl index 47965988dc5..7cc62837a71 100644 --- a/apps/ejabberd/src/mod_muc_room.erl +++ b/apps/ejabberd/src/mod_muc_room.erl @@ -1893,7 +1893,7 @@ make_http_auth_request(From, Nick, Packet, Role, RoomJid, RoomPid, Password, Poo Path = <<"/check_password?from=", FromVal/binary, "&to=", RoomJidVal/binary, "&pass=", PassVal/binary>>, - Result = case mod_http_client:make_request(Pool, Path, <<"GET">>, [], <<>>) of + Result = case mod_http_client:get(Pool, Path, []) of {ok, {<<"200">>, Body}} -> decode_http_auth_response(Body); _ -> error end,