Add support for 304 in thumbnails

pull/186/head
Omar Roth 2018-09-17 09:38:52 -05:00
rodzic 0a4e9e6252
commit 6cb834a18d
1 zmienionych plików z 32 dodań i 13 usunięć

Wyświetl plik

@ -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