diff --git a/src/invidious/routes/feeds.cr b/src/invidious/routes/feeds.cr index b011b480..83eeabd2 100644 --- a/src/invidious/routes/feeds.cr +++ b/src/invidious/routes/feeds.cr @@ -170,7 +170,7 @@ module Invidious::Routes::Feeds "default" => "http://www.w3.org/2005/Atom", } - response = YT_POOL.client &.get("/feeds/videos.xml?channel_id=#{ucid}") + response = YT_POOL.client env, ["Expires", "Cache-Control", "Date"], &.get("/feeds/videos.xml?channel_id=#{ucid}") return error_atom(404, NotFoundException.new("Channel does not exist.")) if response.status_code == 404 rss = XML.parse(response.body) @@ -320,7 +320,7 @@ module Invidious::Routes::Feeds end end - response = YT_POOL.client &.get("/feeds/videos.xml?playlist_id=#{plid}") + response = YT_POOL.client env, ["Expires", "Cache-Control", "Date"], &.get("/feeds/videos.xml?playlist_id=#{plid}") return error_atom(404, NotFoundException.new("Playlist does not exist.")) if response.status_code == 404 document = XML.parse(response.body) diff --git a/src/invidious/yt_backend/connection_pool.cr b/src/invidious/yt_backend/connection_pool.cr index 32780921..ea2dbef6 100644 --- a/src/invidious/yt_backend/connection_pool.cr +++ b/src/invidious/yt_backend/connection_pool.cr @@ -13,7 +13,7 @@ struct YoutubeConnectionPool @pool = build_pool() end - def client(&) + def client(env : HTTP::Server::Context? = nil, headers_to_duplicate : Array(String)? = nil, &) conn = pool.checkout # Proxy needs to be reinstated every time we get a client from the pool conn.proxy = make_configured_http_proxy_client() if CONFIG.http_proxy @@ -29,6 +29,20 @@ struct YoutubeConnectionPool pool.release(conn) end + # Shit way do not use do not replicate this is horrible because how blocks work + if env && headers_to_duplicate + if response.is_a?(HTTP::Client::Response) + youtube_response_headers = response.headers + if youtube_response_headers + headers_to_duplicate.each do |header| + if header_value = youtube_response_headers[header]? + env.response.headers[header] = header_value + end + end + end + end + end + response end