mirror of
https://github.com/iv-org/invidious.git
synced 2024-12-20 13:14:27 -05:00
Catch connection reset when proxying files
This commit is contained in:
parent
267bf289c4
commit
208bb2d72f
@ -4964,11 +4964,12 @@ get "/videoplayback" do |env|
|
|||||||
end
|
end
|
||||||
|
|
||||||
client = make_client(URI.parse(host), proxies, region)
|
client = make_client(URI.parse(host), proxies, region)
|
||||||
|
begin
|
||||||
client.get(url, headers) do |response|
|
client.get(url, headers) do |response|
|
||||||
env.response.status_code = response.status_code
|
env.response.status_code = response.status_code
|
||||||
|
|
||||||
response.headers.each do |key, value|
|
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
|
env.response.headers[key] = value
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -4996,6 +4997,8 @@ get "/videoplayback" do |env|
|
|||||||
|
|
||||||
proxy_file(response, env)
|
proxy_file(response, env)
|
||||||
end
|
end
|
||||||
|
rescue ex
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# We need this so the below route works as expected
|
# We need this so the below route works as expected
|
||||||
@ -5014,9 +5017,10 @@ get "/ggpht/*" do |env|
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
begin
|
||||||
client.get(url, headers) do |response|
|
client.get(url, headers) do |response|
|
||||||
response.headers.each do |key, value|
|
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
|
env.response.headers[key] = value
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -5029,6 +5033,8 @@ get "/ggpht/*" do |env|
|
|||||||
|
|
||||||
proxy_file(response, env)
|
proxy_file(response, env)
|
||||||
end
|
end
|
||||||
|
rescue ex
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
options "/sb/:id/:storyboard/:index" do |env|
|
options "/sb/:id/:storyboard/:index" do |env|
|
||||||
@ -5059,10 +5065,11 @@ get "/sb/:id/:storyboard/:index" do |env|
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
begin
|
||||||
client.get(url, headers) do |response|
|
client.get(url, headers) do |response|
|
||||||
env.response.status_code = response.status_code
|
env.response.status_code = response.status_code
|
||||||
response.headers.each do |key, value|
|
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
|
env.response.headers[key] = value
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -5075,6 +5082,8 @@ get "/sb/:id/:storyboard/:index" do |env|
|
|||||||
|
|
||||||
proxy_file(response, env)
|
proxy_file(response, env)
|
||||||
end
|
end
|
||||||
|
rescue ex
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
get "/vi/:id/:name" do |env|
|
get "/vi/:id/:name" do |env|
|
||||||
@ -5101,10 +5110,11 @@ get "/vi/:id/:name" do |env|
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
begin
|
||||||
client.get(url, headers) do |response|
|
client.get(url, headers) do |response|
|
||||||
env.response.status_code = response.status_code
|
env.response.status_code = response.status_code
|
||||||
response.headers.each do |key, value|
|
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
|
env.response.headers[key] = value
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -5117,6 +5127,8 @@ get "/vi/:id/:name" do |env|
|
|||||||
|
|
||||||
proxy_file(response, env)
|
proxy_file(response, env)
|
||||||
end
|
end
|
||||||
|
rescue ex
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Undocumented, creates anonymous playlist with specified 'video_ids'
|
# Undocumented, creates anonymous playlist with specified 'video_ids'
|
||||||
|
@ -639,7 +639,6 @@ def proxy_file(response, env)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
begin
|
|
||||||
if response.headers.includes_word?("Content-Encoding", "gzip")
|
if response.headers.includes_word?("Content-Encoding", "gzip")
|
||||||
Gzip::Writer.open(env.response) do |deflate|
|
Gzip::Writer.open(env.response) do |deflate|
|
||||||
copy_in_chunks(response.body_io, deflate)
|
copy_in_chunks(response.body_io, deflate)
|
||||||
@ -651,8 +650,6 @@ def proxy_file(response, env)
|
|||||||
else
|
else
|
||||||
copy_in_chunks(response.body_io, env.response)
|
copy_in_chunks(response.body_io, env.response)
|
||||||
end
|
end
|
||||||
rescue ex
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# https://stackoverflow.com/a/44802810 <3
|
# https://stackoverflow.com/a/44802810 <3
|
||||||
|
Loading…
Reference in New Issue
Block a user