@@ -12,6 +12,15 @@ module Invidious
12
12
end
13
13
14
14
class HTTPClient < HTTP::Client
15
+ def initialize (uri : URI , tls : TLSContext = nil , allow_auto_reconnect : Bool = true )
16
+ tls = HTTP ::Client .tls_flag(uri, tls)
17
+ host = HTTP ::Client .validate_host(uri)
18
+
19
+ super (host, uri.port, tls)
20
+
21
+ @reconnect = allow_auto_reconnect
22
+ end
23
+
15
24
def initialize (uri : URI , tls : TLSContext = nil , force_resolve : Socket ::Family = Socket ::Family ::UNSPEC )
16
25
tls = HTTP ::Client .tls_flag(uri, tls)
17
26
@@ -72,14 +81,21 @@ def add_yt_headers(request)
72
81
end
73
82
end
74
83
75
- def make_client (url : URI , region = nil , force_resolve : Bool = false , force_youtube_headers : Bool = true , use_http_proxy : Bool = true )
84
+ def make_client (
85
+ url : URI ,
86
+ region = nil ,
87
+ force_resolve : Bool = false ,
88
+ force_youtube_headers : Bool = true ,
89
+ use_http_proxy : Bool = true ,
90
+ allow_auto_reconnect : Bool = true ,
91
+ )
76
92
if CONFIG .http_proxy && use_http_proxy
77
93
client = Invidious ::HTTPClient .new(url)
78
94
client.proxy = make_configured_http_proxy_client() if CONFIG .http_proxy && use_http_proxy
79
95
elsif force_resolve
80
96
client = Invidious ::HTTPClient .new(url, force_resolve: CONFIG .force_resolve)
81
97
else
82
- client = Invidious ::HTTPClient .new(url)
98
+ client = Invidious ::HTTPClient .new(url, allow_auto_reconnect: allow_auto_reconnect )
83
99
end
84
100
85
101
client.before_request { |r | add_yt_headers(r) } if url.host.try & .ends_with?(" youtube.com" ) || force_youtube_headers
0 commit comments