From 438c770c79755478e0413b7951fedc1dc6e00e88 Mon Sep 17 00:00:00 2001 From: Sergey Prokhorov Date: Mon, 26 Aug 2019 21:04:54 +0200 Subject: [PATCH] Use httpc ipv4 options only on OTP 21+ --- src/mtp_config.erl | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/mtp_config.erl b/src/mtp_config.erl index b33f552..e501c82 100644 --- a/src/mtp_config.erl +++ b/src/mtp_config.erl @@ -257,14 +257,20 @@ update_ip([Url | Fallbacks]) -> update_ip([]) -> 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) -> {ok, Vsn} = application:get_key(mtproto_proxy, vsn), UserAgent = "MTProtoProxy/" ++ Vsn ++ " (+https://github.com/seriyps/mtproto_proxy)", Headers = [{"User-Agent", UserAgent}], - %% XXX: ipfamily only works on OTP >= 20.3.4; see OTP 2dc08b47e6a5ea759781479593c55bb5776cd828 {ok, {{_, 200, _}, _, Body}} = - httpc:request(get, {Url, Headers}, [{timeout, 3000}], - [{socket_opts, [{ipfamily, inet}]}]), + httpc:request(get, {Url, Headers}, [{timeout, 3000}], ?OPTS), {ok, Body}. random_choice(L) ->