Catch connection reset when proxying files

pull/553/head
Omar Roth 6 years ago
parent 267bf289c4
commit 208bb2d72f
No known key found for this signature in database
GPG Key ID: B8254FB7EC3D37F2

@ -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,19 +639,16 @@ 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)
end
elsif response.headers.includes_word?("Content-Encoding", "deflate")
Flate::Writer.open(env.response) do |deflate|
copy_in_chunks(response.body_io, deflate)
end
else
copy_in_chunks(response.body_io, env.response)
end end
rescue ex elsif response.headers.includes_word?("Content-Encoding", "deflate")
Flate::Writer.open(env.response) do |deflate|
copy_in_chunks(response.body_io, deflate)
end
else
copy_in_chunks(response.body_io, env.response)
end end
end end

Loading…
Cancel
Save