forked from midou/invidious
Merge pull request #1600 from jksladjflkjsadflkjsadf/closeclients
Close http clients after use
This commit is contained in:
@@ -108,7 +108,9 @@ def filter_proxies(proxies)
|
||||
proxy = HTTPProxy.new(proxy_host: proxy[:ip], proxy_port: proxy[:port])
|
||||
client.set_proxy(proxy)
|
||||
|
||||
client.head("/").status_code == 200
|
||||
status_ok = client.head("/").status_code == 200
|
||||
client.close
|
||||
status_ok
|
||||
rescue ex
|
||||
false
|
||||
end
|
||||
@@ -132,6 +134,7 @@ def get_nova_proxies(country_code = "US")
|
||||
headers["Referer"] = "https://www.proxynova.com/proxy-server-list/country-#{country_code}/"
|
||||
|
||||
response = client.get("/proxy-server-list/country-#{country_code}/", headers)
|
||||
client.close
|
||||
document = XML.parse_html(response.body)
|
||||
|
||||
proxies = [] of {ip: String, port: Int32, score: Float64}
|
||||
@@ -177,6 +180,7 @@ def get_spys_proxies(country_code = "US")
|
||||
}
|
||||
|
||||
response = client.post("/free-proxy-list/#{country_code}/", headers, form: body)
|
||||
client.close
|
||||
20.times do
|
||||
if response.status_code == 200
|
||||
break
|
||||
|
@@ -101,6 +101,15 @@ def make_client(url : URI, region = nil)
|
||||
return client
|
||||
end
|
||||
|
||||
def make_client(url : URI, region = nil, &block)
|
||||
client = make_client(url, region)
|
||||
begin
|
||||
yield client
|
||||
ensure
|
||||
client.close
|
||||
end
|
||||
end
|
||||
|
||||
def decode_length_seconds(string)
|
||||
length_seconds = string.gsub(/[^0-9:]/, "").split(":").map &.to_i
|
||||
length_seconds = [0] * (3 - length_seconds.size) + length_seconds
|
||||
@@ -361,7 +370,7 @@ def subscribe_pubsub(topic, key, config)
|
||||
"hub.secret" => key.to_s,
|
||||
}
|
||||
|
||||
return make_client(PUBSUB_URL).post("/subscribe", form: body)
|
||||
return make_client(PUBSUB_URL, &.post("/subscribe", form: body))
|
||||
end
|
||||
|
||||
def parse_range(range)
|
||||
|
Reference in New Issue
Block a user