Cleanup request headers

This commit is contained in:
Omar Roth 2020-05-08 09:00:53 -05:00
parent 75450dcdbc
commit 454ae8656a
No known key found for this signature in database
GPG key ID: B8254FB7EC3D37F2

View file

@ -4538,10 +4538,8 @@ get "/api/v1/search/suggestions" do |env|
query ||= "" query ||= ""
begin begin
client = QUIC::Client.new("suggestqueries.google.com") headers = HTTP::Headers{":authority" => "suggestqueries.google.com"}
client.family = CONFIG.force_resolve || Socket::Family::INET 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
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
body = response[35..-2] body = response[35..-2]
body = JSON.parse(body).as_a body = JSON.parse(body).as_a
@ -5671,8 +5669,7 @@ end
get "/ggpht/*" do |env| get "/ggpht/*" do |env|
url = env.request.path.lchop("/ggpht") url = env.request.path.lchop("/ggpht")
headers = HTTP::Headers.new headers = HTTP::Headers{":authority" => "yt3.ggpht.com"}
headers[":authority"] = "yt3.ggpht.com"
REQUEST_HEADERS_WHITELIST.each do |header| REQUEST_HEADERS_WHITELIST.each do |header|
if env.request.headers[header]? if env.request.headers[header]?
headers[header] = 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 url = env.request.resource
headers = HTTP::Headers.new headers = HTTP::Headers{":authority" => "i9.ytimg.com"}
headers[":authority"] = "i9.ytimg.com"
REQUEST_HEADERS_WHITELIST.each do |header| REQUEST_HEADERS_WHITELIST.each do |header|
if env.request.headers[header]? if env.request.headers[header]?
headers[header] = 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"] id = env.params.url["id"]
name = env.params.url["name"] name = env.params.url["name"]
headers = HTTP::Headers.new headers = HTTP::Headers{":authority" => "i.ytimg.com"}
headers[":authority"] = "i.ytimg.com"
if name == "maxres.jpg" if name == "maxres.jpg"
build_thumbnails(id, config, Kemal.config).each do |thumb| build_thumbnails(id, config, Kemal.config).each do |thumb|
@ -5864,8 +5859,8 @@ get "/vi/:id/:name" do |env|
end end
get "/Captcha" do |env| get "/Captcha" do |env|
client = make_client(LOGIN_URL) headers = HTTP::Headers{":authority" => "accounts.google.com"}
response = client.get(env.request.resource) response = YT_POOL.client &.get(env.request.resource, headers)
env.response.headers["Content-Type"] = response.headers["Content-Type"] env.response.headers["Content-Type"] = response.headers["Content-Type"]
response.body response.body
end end