Use httpc ipv4 options only on OTP 21+

parent 2a5d6463
...@@ -257,14 +257,20 @@ update_ip([Url | Fallbacks]) -> ...@@ -257,14 +257,20 @@ update_ip([Url | Fallbacks]) ->
update_ip([]) -> update_ip([]) ->
error(ip_lookup_failed). error(ip_lookup_failed).
-ifdef(OTP_VERSION).
%% XXX: ipfamily only works on OTP >= 20.3.4; see OTP 2dc08b47e6a5ea759781479593c55bb5776cd828
%% Enable it for OTP 21+ for simplicity
-define(OPTS, [{socket_opts, [{ipfamily, inet}]}]).
-else.
-define(OPTS, []).
-endif.
http_get(Url) -> http_get(Url) ->
{ok, Vsn} = application:get_key(mtproto_proxy, vsn), {ok, Vsn} = application:get_key(mtproto_proxy, vsn),
UserAgent = "MTProtoProxy/" ++ Vsn ++ " (+https://github.com/seriyps/mtproto_proxy)", UserAgent = "MTProtoProxy/" ++ Vsn ++ " (+https://github.com/seriyps/mtproto_proxy)",
Headers = [{"User-Agent", UserAgent}], Headers = [{"User-Agent", UserAgent}],
%% XXX: ipfamily only works on OTP >= 20.3.4; see OTP 2dc08b47e6a5ea759781479593c55bb5776cd828
{ok, {{_, 200, _}, _, Body}} = {ok, {{_, 200, _}, _, Body}} =
httpc:request(get, {Url, Headers}, [{timeout, 3000}], httpc:request(get, {Url, Headers}, [{timeout, 3000}], ?OPTS),
[{socket_opts, [{ipfamily, inet}]}]),
{ok, Body}. {ok, Body}.
random_choice(L) -> random_choice(L) ->
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment