mirror of https://github.com/iv-org/invidious.git
Fix response for proxied assets
This commit is contained in:
parent
b52e6c99ab
commit
ab4df7e078
|
@ -5079,17 +5079,7 @@ get "/videoplayback" do |env|
|
||||||
|
|
||||||
env.response.headers["Access-Control-Allow-Origin"] = "*"
|
env.response.headers["Access-Control-Allow-Origin"] = "*"
|
||||||
|
|
||||||
begin
|
proxy_file(response, env)
|
||||||
chunk_size = 4096
|
|
||||||
size = 1
|
|
||||||
while size > 0
|
|
||||||
size = IO.copy(response.body_io, env.response.output, chunk_size)
|
|
||||||
env.response.flush
|
|
||||||
Fiber.yield
|
|
||||||
end
|
|
||||||
rescue ex
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -5119,28 +5109,7 @@ get "/ggpht/*" do |env|
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
chunk_size = 4096
|
proxy_file(response, env)
|
||||||
size = 1
|
|
||||||
if response.headers.includes_word?("Content-Encoding", "gzip")
|
|
||||||
Gzip::Writer.open(env.response) do |deflate|
|
|
||||||
until size == 0
|
|
||||||
size = IO.copy(response.body_io, deflate)
|
|
||||||
env.response.flush
|
|
||||||
end
|
|
||||||
end
|
|
||||||
elsif response.headers.includes_word?("Content-Encoding", "deflate")
|
|
||||||
Flate::Writer.open(env.response) do |deflate|
|
|
||||||
until size == 0
|
|
||||||
size = IO.copy(response.body_io, deflate)
|
|
||||||
env.response.flush
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
until size == 0
|
|
||||||
size = IO.copy(response.body_io, env.response, chunk_size)
|
|
||||||
env.response.flush
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -5182,28 +5151,7 @@ get "/sb/:id/:storyboard/:index" do |env|
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
chunk_size = 4096
|
proxy_file(response, env)
|
||||||
size = 1
|
|
||||||
if response.headers.includes_word?("Content-Encoding", "gzip")
|
|
||||||
Gzip::Writer.open(env.response) do |deflate|
|
|
||||||
until size == 0
|
|
||||||
size = IO.copy(response.body_io, deflate)
|
|
||||||
env.response.flush
|
|
||||||
end
|
|
||||||
end
|
|
||||||
elsif response.headers.includes_word?("Content-Encoding", "deflate")
|
|
||||||
Flate::Writer.open(env.response) do |deflate|
|
|
||||||
until size == 0
|
|
||||||
size = IO.copy(response.body_io, deflate)
|
|
||||||
env.response.flush
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
until size == 0
|
|
||||||
size = IO.copy(response.body_io, env.response, chunk_size)
|
|
||||||
env.response.flush
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -5241,28 +5189,7 @@ get "/vi/:id/:name" do |env|
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
chunk_size = 4096
|
proxy_file(response, env)
|
||||||
size = 1
|
|
||||||
if response.headers.includes_word?("Content-Encoding", "gzip")
|
|
||||||
Gzip::Writer.open(env.response) do |deflate|
|
|
||||||
until size == 0
|
|
||||||
size = IO.copy(response.body_io, deflate)
|
|
||||||
env.response.flush
|
|
||||||
end
|
|
||||||
end
|
|
||||||
elsif response.headers.includes_word?("Content-Encoding", "deflate")
|
|
||||||
Flate::Writer.open(env.response) do |deflate|
|
|
||||||
until size == 0
|
|
||||||
size = IO.copy(response.body_io, deflate)
|
|
||||||
env.response.flush
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
until size == 0
|
|
||||||
size = IO.copy(response.body_io, env.response, chunk_size)
|
|
||||||
env.response.flush
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -629,3 +629,17 @@ def cache_annotation(db, id, annotations)
|
||||||
db.exec("INSERT INTO annotations VALUES ($1, $2) ON CONFLICT DO NOTHING", id, annotations)
|
db.exec("INSERT INTO annotations VALUES ($1, $2) ON CONFLICT DO NOTHING", id, annotations)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def proxy_file(response, env)
|
||||||
|
if response.headers.includes_word?("Content-Encoding", "gzip")
|
||||||
|
Gzip::Writer.open(env.response) do |deflate|
|
||||||
|
IO.copy(response.body_io, deflate)
|
||||||
|
end
|
||||||
|
elsif response.headers.includes_word?("Content-Encoding", "deflate")
|
||||||
|
Flate::Writer.open(env.response) do |deflate|
|
||||||
|
IO.copy(response.body_io, deflate)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
IO.copy(response.body_io, env.response)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in New Issue