Invidious is an alternative front-end to YouTube
Use make_client instead of calling HTTP::Client (#4709)
Samantaz Fox42da2547e388
diff --cc src/invidious/yt_backend/connection_pool.crindex c7c4c675,bff4df72..083c10c2--- a/src/invidious/yt_backend/connection_pool.cr+++ b/src/invidious/yt_backend/connection_pool.cr@@@ -22,12 -30,7 +22,9 @@@ struct YoutubeConnectionPooresponse = yield connrescue exconn.close+- conn = HTTP::Client.new(url)- conn.proxy = make_configured_http_proxy_client() if CONFIG.http_proxy- conn.family = CONFIG.force_resolve- conn.family = Socket::Family::INET if conn.family == Socket::Family::UNSPEC- conn.before_request { |r| add_yt_headers(r) } if url.host == "www.youtube.com"+ conn = make_client(url, force_resolve: true)++response = yield connensurepool.release(conn)@@@ -47,23 -46,8 +40,24 @@@endend+def add_yt_headers(request)+ request.headers.delete("User-Agent") if request.headers["User-Agent"] == "Crystal"+ request.headers["User-Agent"] ||= "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36"++ request.headers["Accept-Charset"] ||= "ISO-8859-1,utf-8;q=0.7,*;q=0.7"+ request.headers["Accept"] ||= "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"+ request.headers["Accept-Language"] ||= "en-us,en;q=0.5"++ # Preserve original cookies and add new YT consent cookie for EU servers+ request.headers["Cookie"] = "#{request.headers["cookie"]?}; CONSENT=PENDING+#{Random.rand(100..999)}"+ if !CONFIG.cookies.empty?+ request.headers["Cookie"] = "#{(CONFIG.cookies.map { |c| "#{c.name}=#{c.value}" }).join("; ")}; #{request.headers["cookie"]?}"+ end+end+- def make_client(url : URI, region = nil, force_resolve : Bool = false)+ def make_client(url : URI, region = nil, force_resolve : Bool = false, force_youtube_headers : Bool = false)client = HTTP::Client.new(url)++ client.proxy = make_configured_http_proxy_client() if CONFIG.http_proxy# Force the usage of a specific configured IP Familyif force_resolve