Refactor proxy_list into global

This commit is contained in:
Omar Roth
2019-06-28 21:17:56 -05:00
parent a58f5a925a
commit e30d70b6d4
7 changed files with 42 additions and 55 deletions

View File

@@ -18,24 +18,13 @@ def elapsed_text(elapsed)
"#{(millis * 1000).round(2)}µs"
end
def make_client(url : URI, proxies = {} of String => Array({ip: String, port: Int32}), region = nil)
context = nil
if url.scheme == "https"
context = OpenSSL::SSL::Context::Client.new
context.add_options(
OpenSSL::SSL::Options::ALL |
OpenSSL::SSL::Options::NO_SSL_V2 |
OpenSSL::SSL::Options::NO_SSL_V3
)
end
client = HTTPClient.new(url, context)
client.read_timeout = 10.seconds
client.connect_timeout = 10.seconds
def make_client(url : URI, region = nil)
client = HTTPClient.new(url)
client.read_timeout = 15.seconds
client.connect_timeout = 15.seconds
if region
proxies[region]?.try &.sample(40).each do |proxy|
PROXY_LIST[region]?.try &.sample(40).each do |proxy|
begin
proxy = HTTPProxy.new(proxy_host: proxy[:ip], proxy_port: proxy[:port])
client.set_proxy(proxy)