|
|
@ -3,31 +3,61 @@ module Invidious::Routes::Images
|
|
|
|
def self.ggpht(env)
|
|
|
|
def self.ggpht(env)
|
|
|
|
url = env.request.path.lchop("/ggpht")
|
|
|
|
url = env.request.path.lchop("/ggpht")
|
|
|
|
|
|
|
|
|
|
|
|
headers = HTTP::Headers{":authority" => "yt3.ggpht.com"}
|
|
|
|
headers = (
|
|
|
|
|
|
|
|
{% unless flag?(:disable_quic) %}
|
|
|
|
|
|
|
|
if CONFIG.use_quic
|
|
|
|
|
|
|
|
HTTP::Headers{":authority" => "yt3.ggpht.com"}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
HTTP::Headers.new
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
{% else %}
|
|
|
|
|
|
|
|
HTTP::Headers.new
|
|
|
|
|
|
|
|
{% end %}
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
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]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
begin
|
|
|
|
# We're encapsulating this into a proc in order to easily reuse this
|
|
|
|
YT_POOL.client &.get(url, headers) do |response|
|
|
|
|
# portion of the code for each request block below.
|
|
|
|
env.response.status_code = response.status_code
|
|
|
|
request_proc = ->(response : HTTP::Client::Response) {
|
|
|
|
response.headers.each do |key, value|
|
|
|
|
env.response.status_code = response.status_code
|
|
|
|
if !RESPONSE_HEADERS_BLACKLIST.includes?(key.downcase)
|
|
|
|
response.headers.each do |key, value|
|
|
|
|
env.response.headers[key] = value
|
|
|
|
if !RESPONSE_HEADERS_BLACKLIST.includes?(key.downcase)
|
|
|
|
end
|
|
|
|
env.response.headers[key] = value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
env.response.headers["Access-Control-Allow-Origin"] = "*"
|
|
|
|
env.response.headers["Access-Control-Allow-Origin"] = "*"
|
|
|
|
|
|
|
|
|
|
|
|
if response.status_code >= 300
|
|
|
|
|
|
|
|
env.response.headers.delete("Transfer-Encoding")
|
|
|
|
|
|
|
|
break
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proxy_file(response, env)
|
|
|
|
if response.status_code >= 300
|
|
|
|
|
|
|
|
env.response.headers.delete("Transfer-Encoding")
|
|
|
|
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proxy_file(response, env)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
begin
|
|
|
|
|
|
|
|
{% unless flag?(:disable_quic) %}
|
|
|
|
|
|
|
|
if CONFIG.use_quic
|
|
|
|
|
|
|
|
YT_POOL.client &.get(url, headers) do |resp|
|
|
|
|
|
|
|
|
return request_proc.call(resp)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
HTTP::Client.get("yt3.ggpht.com#{url}") do |resp|
|
|
|
|
|
|
|
|
return request_proc.call(resp)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
{% else %}
|
|
|
|
|
|
|
|
# This can likely be optimized into a (small) pool sometime in the future.
|
|
|
|
|
|
|
|
HTTP::Client.get("yt3.ggpht.com#{url}") do |resp|
|
|
|
|
|
|
|
|
return request_proc.call(resp)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
{% end %}
|
|
|
|
rescue ex
|
|
|
|
rescue ex
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|