mirror of
https://git.nadeko.net/Fijxu/invidious.git
synced 2025-12-15 09:35:09 +00:00
Close http clients after using
The crystal http client maintains a keepalive connection to the other server which stays alive for some time. This should be closed if the client instance is not used again to avoid hogging resources
This commit is contained in:
@@ -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