mirror of
https://gitea.invidious.io/iv-org/invidious-copy-2023-06-08.git
synced 2024-08-15 00:53:38 +00:00
Catch connection reset when proxying files
This commit is contained in:
parent
267bf289c4
commit
208bb2d72f
2 changed files with 25 additions and 16 deletions
|
@ -4964,11 +4964,12 @@ get "/videoplayback" do |env|
|
|||
end
|
||||
|
||||
client = make_client(URI.parse(host), proxies, region)
|
||||
begin
|
||||
client.get(url, headers) do |response|
|
||||
env.response.status_code = response.status_code
|
||||
|
||||
response.headers.each do |key, value|
|
||||
if !{"Access-Control-Allow-Origin", "Alt-Svc"}.includes? key
|
||||
if !{"Access-Control-Allow-Origin", "Alt-Svc", "Server"}.includes? key
|
||||
env.response.headers[key] = value
|
||||
end
|
||||
end
|
||||
|
@ -4996,6 +4997,8 @@ get "/videoplayback" do |env|
|
|||
|
||||
proxy_file(response, env)
|
||||
end
|
||||
rescue ex
|
||||
end
|
||||
end
|
||||
|
||||
# We need this so the below route works as expected
|
||||
|
@ -5014,9 +5017,10 @@ get "/ggpht/*" do |env|
|
|||
end
|
||||
end
|
||||
|
||||
begin
|
||||
client.get(url, headers) do |response|
|
||||
response.headers.each do |key, value|
|
||||
if !{"Access-Control-Allow-Origin", "Alt-Svc"}.includes? key
|
||||
if !{"Access-Control-Allow-Origin", "Alt-Svc", "Server"}.includes? key
|
||||
env.response.headers[key] = value
|
||||
end
|
||||
end
|
||||
|
@ -5029,6 +5033,8 @@ get "/ggpht/*" do |env|
|
|||
|
||||
proxy_file(response, env)
|
||||
end
|
||||
rescue ex
|
||||
end
|
||||
end
|
||||
|
||||
options "/sb/:id/:storyboard/:index" do |env|
|
||||
|
@ -5059,10 +5065,11 @@ get "/sb/:id/:storyboard/:index" do |env|
|
|||
end
|
||||
end
|
||||
|
||||
begin
|
||||
client.get(url, headers) do |response|
|
||||
env.response.status_code = response.status_code
|
||||
response.headers.each do |key, value|
|
||||
if !{"Access-Control-Allow-Origin", "Alt-Svc"}.includes? key
|
||||
if !{"Access-Control-Allow-Origin", "Alt-Svc", "Server"}.includes? key
|
||||
env.response.headers[key] = value
|
||||
end
|
||||
end
|
||||
|
@ -5075,6 +5082,8 @@ get "/sb/:id/:storyboard/:index" do |env|
|
|||
|
||||
proxy_file(response, env)
|
||||
end
|
||||
rescue ex
|
||||
end
|
||||
end
|
||||
|
||||
get "/vi/:id/:name" do |env|
|
||||
|
@ -5101,10 +5110,11 @@ get "/vi/:id/:name" do |env|
|
|||
end
|
||||
end
|
||||
|
||||
begin
|
||||
client.get(url, headers) do |response|
|
||||
env.response.status_code = response.status_code
|
||||
response.headers.each do |key, value|
|
||||
if !{"Access-Control-Allow-Origin", "Alt-Svc"}.includes? key
|
||||
if !{"Access-Control-Allow-Origin", "Alt-Svc", "Server"}.includes? key
|
||||
env.response.headers[key] = value
|
||||
end
|
||||
end
|
||||
|
@ -5117,6 +5127,8 @@ get "/vi/:id/:name" do |env|
|
|||
|
||||
proxy_file(response, env)
|
||||
end
|
||||
rescue ex
|
||||
end
|
||||
end
|
||||
|
||||
# Undocumented, creates anonymous playlist with specified 'video_ids'
|
||||
|
|
|
@ -639,7 +639,6 @@ def proxy_file(response, env)
|
|||
return
|
||||
end
|
||||
|
||||
begin
|
||||
if response.headers.includes_word?("Content-Encoding", "gzip")
|
||||
Gzip::Writer.open(env.response) do |deflate|
|
||||
copy_in_chunks(response.body_io, deflate)
|
||||
|
@ -651,8 +650,6 @@ def proxy_file(response, env)
|
|||
else
|
||||
copy_in_chunks(response.body_io, env.response)
|
||||
end
|
||||
rescue ex
|
||||
end
|
||||
end
|
||||
|
||||
# https://stackoverflow.com/a/44802810 <3
|
||||
|
|
Loading…
Reference in a new issue