From 454ae8656a61188082e54e75c637e99425e0e2ac Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Fri, 8 May 2020 09:00:53 -0500 Subject: [PATCH] Cleanup request headers --- src/invidious.cr | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/invidious.cr b/src/invidious.cr index 2a493a46..6a197795 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -4538,10 +4538,8 @@ get "/api/v1/search/suggestions" do |env| query ||= "" begin - client = QUIC::Client.new("suggestqueries.google.com") - client.family = CONFIG.force_resolve || Socket::Family::INET - client.family = Socket::Family::INET if client.family == Socket::Family::UNSPEC - response = client.get("/complete/search?hl=en&gl=#{region}&client=youtube&ds=yt&q=#{URI.encode_www_form(query)}&callback=suggestCallback").body + headers = HTTP::Headers{":authority" => "suggestqueries.google.com"} + response = YT_POOL.client &.get("/complete/search?hl=en&gl=#{region}&client=youtube&ds=yt&q=#{URI.encode_www_form(query)}&callback=suggestCallback", headers).body body = response[35..-2] body = JSON.parse(body).as_a @@ -5671,8 +5669,7 @@ end get "/ggpht/*" do |env| url = env.request.path.lchop("/ggpht") - headers = HTTP::Headers.new - headers[":authority"] = "yt3.ggpht.com" + headers = HTTP::Headers{":authority" => "yt3.ggpht.com"} REQUEST_HEADERS_WHITELIST.each do |header| if env.request.headers[header]? headers[header] = env.request.headers[header] @@ -5758,8 +5755,7 @@ get "/s_p/:id/:name" do |env| url = env.request.resource - headers = HTTP::Headers.new - headers[":authority"] = "i9.ytimg.com" + headers = HTTP::Headers{":authority" => "i9.ytimg.com"} REQUEST_HEADERS_WHITELIST.each do |header| if env.request.headers[header]? headers[header] = env.request.headers[header] @@ -5822,8 +5818,7 @@ get "/vi/:id/:name" do |env| id = env.params.url["id"] name = env.params.url["name"] - headers = HTTP::Headers.new - headers[":authority"] = "i.ytimg.com" + headers = HTTP::Headers{":authority" => "i.ytimg.com"} if name == "maxres.jpg" build_thumbnails(id, config, Kemal.config).each do |thumb| @@ -5864,8 +5859,8 @@ get "/vi/:id/:name" do |env| end get "/Captcha" do |env| - client = make_client(LOGIN_URL) - response = client.get(env.request.resource) + headers = HTTP::Headers{":authority" => "accounts.google.com"} + response = YT_POOL.client &.get(env.request.resource, headers) env.response.headers["Content-Type"] = response.headers["Content-Type"] response.body end