From 351ecfae0f249347a48c0d9daf2e492fdacce89c Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Wed, 3 Jul 2019 13:13:40 -0500 Subject: [PATCH] Fix body when proxying assets with status code > 300 --- src/invidious.cr | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/invidious.cr b/src/invidious.cr index 97d57b61..b4df40cf 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -4695,18 +4695,19 @@ get "/ggpht/*" do |env| begin client.get(url, headers) do |response| + env.response.status_code = response.status_code response.headers.each do |key, value| if !RESPONSE_HEADERS_BLACKLIST.includes? key env.response.headers[key] = value end end - if response.status_code == 304 + env.response.headers["Access-Control-Allow-Origin"] = "*" + + if response.status_code >= 300 break end - env.response.headers["Access-Control-Allow-Origin"] = "*" - proxy_file(response, env) end rescue ex @@ -4750,12 +4751,12 @@ get "/sb/:id/:storyboard/:index" do |env| end end - if response.status_code >= 400 + env.response.headers["Access-Control-Allow-Origin"] = "*" + + if response.status_code >= 300 break end - env.response.headers["Access-Control-Allow-Origin"] = "*" - proxy_file(response, env) end rescue ex @@ -4795,12 +4796,12 @@ get "/vi/:id/:name" do |env| end end - if response.status_code == 304 + env.response.headers["Access-Control-Allow-Origin"] = "*" + + if response.status_code >= 300 break end - env.response.headers["Access-Control-Allow-Origin"] = "*" - proxy_file(response, env) end rescue ex