Add user-agent to outgoing HTTP requests

parent ef738070
......@@ -124,11 +124,11 @@ update(State, _) ->
end.
update_key(Tab) ->
{ok, {{_, 200, _}, _, Body}} = httpc:request(?SECRET_URL),
{ok, Body} = http_get(?SECRET_URL),
true = ets:insert(Tab, {key, list_to_binary(Body)}).
update_config(Tab) ->
{ok, {{_, 200, _}, _, Body}} = httpc:request(?CONFIG_URL),
{ok, Body} = http_get(?CONFIG_URL),
Downstreams = parse_config(Body),
Range = get_range(Downstreams),
update_downstreams(Downstreams, Tab),
......@@ -174,7 +174,7 @@ update_ip() ->
update_ip([Url | Fallbacks]) ->
try
{ok, {{_, 200, _}, _, Body}} = httpc:request(Url),
{ok, Body} = http_get(Url),
IpStr= string:trim(Body),
{ok, _} = inet:parse_ipv4strict_address(IpStr), %assert
application:set_env(?APP, external_ip, IpStr)
......@@ -186,6 +186,14 @@ update_ip([Url | Fallbacks]) ->
update_ip([]) ->
error(ip_lookup_failed).
http_get(Url) ->
{ok, Vsn} = application:get_key(mtproto_proxy, vsn),
UserAgent = "MTProtoProxy/" ++ Vsn ++ " (+https://github.com/seriyps/mtproto_proxy)",
Headers = [{"User-Agent", UserAgent}],
{ok, {{_, 200, _}, _, Body}} =
httpc:request(get, {Url, Headers}, [{timeout, 3000}], []),
{ok, Body}.
-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
......
{application, mtproto_proxy,
[{description, "An OTP application"},
{vsn, "0.2.0"},
{vsn, "0.3.0"},
{registered, []},
{mod, { mtproto_proxy_app, []}},
{applications,
......
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