mirror of
https://github.com/seriyps/mtproto_proxy.git
synced 2026-08-04 15:19:47 +00:00
Add user-agent to outgoing HTTP requests
This commit is contained in:
parent
ef7380700f
commit
1253fdc844
2 changed files with 12 additions and 4 deletions
|
|
@ -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").
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{application, mtproto_proxy,
|
||||
[{description, "An OTP application"},
|
||||
{vsn, "0.2.0"},
|
||||
{vsn, "0.3.0"},
|
||||
{registered, []},
|
||||
{mod, { mtproto_proxy_app, []}},
|
||||
{applications,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue