mirror of
https://gitea.invidious.io/iv-org/invidious-copy-2022-04-11.git
synced 2024-08-15 00:43:26 +00:00
Add support for 304 in thumbnails
This commit is contained in:
parent
0a4e9e6252
commit
6cb834a18d
1 changed files with 32 additions and 13 deletions
|
@ -3003,26 +3003,45 @@ get "/vi/:id/:name" do |env|
|
|||
end
|
||||
url = "/vi/#{id}/#{name}"
|
||||
|
||||
client.get(url) do |response|
|
||||
env.response.status_code = response.status_code
|
||||
headers = env.request.headers
|
||||
headers.delete("Host")
|
||||
headers.delete("Cookie")
|
||||
headers.delete("User-Agent")
|
||||
headers.delete("Referer")
|
||||
|
||||
client.get(url, headers) do |response|
|
||||
env.response.status_code = response.status_code
|
||||
puts response.headers.inspect
|
||||
response.headers.each do |key, value|
|
||||
env.response.headers[key] = value
|
||||
end
|
||||
|
||||
env.response.headers["Access-Control-Allow-Origin"] = "*"
|
||||
|
||||
begin
|
||||
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
|
||||
if response.status_code == 304
|
||||
break
|
||||
end
|
||||
|
||||
chunk_size = 4096
|
||||
size = chunk_size
|
||||
if response.headers.includes_word?("Content-Encoding", "gzip")
|
||||
Gzip::Writer.open(env.response) do |deflate|
|
||||
until size < chunk_size
|
||||
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 < chunk_size
|
||||
size = IO.copy(response.body_io, deflate)
|
||||
env.response.flush
|
||||
end
|
||||
end
|
||||
else
|
||||
until size < chunk_size
|
||||
size = IO.copy(response.body_io, env.response, chunk_size)
|
||||
env.response.flush
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue