Add 'region' parameter for bypassing region locks

This commit is contained in:
Omar Roth
2018-11-17 17:33:30 -06:00
parent 879586d7f5
commit 16964ca6ce
3 changed files with 28 additions and 12 deletions

View File

@@ -18,16 +18,28 @@ def elapsed_text(elapsed)
"#{(millis * 1000).round(2)}µs"
end
def make_client(url)
def make_client(url, proxies = {} of String => Array({ip: String, port: Int32}), region = nil)
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
)
client = HTTP::Client.new(url, context)
client = HTTPClient.new(url, context)
client.read_timeout = 10.seconds
client.connect_timeout = 10.seconds
if region
proxies[region]?.try &.each do |proxy|
begin
proxy = HTTPProxy.new(proxy_host: proxy[:ip], proxy_port: proxy[:port])
client.set_proxy(proxy)
break
rescue ex
end
end
end
return client
end