summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOmar Roth <omarroth@hotmail.com>2018-09-17 09:38:52 -0500
committerOmar Roth <omarroth@hotmail.com>2018-09-17 09:38:52 -0500
commit6cb834a18d770f859719102af78a018cc53e03f1 (patch)
tree366c8bbd599134a1b15945431b186ed0414e6294 /src
parent0a4e9e62526fbae2e0d139a9e53f8712f7e5d6a0 (diff)
downloadinvidious-6cb834a18d770f859719102af78a018cc53e03f1.tar.gz
invidious-6cb834a18d770f859719102af78a018cc53e03f1.tar.bz2
invidious-6cb834a18d770f859719102af78a018cc53e03f1.zip
Add support for 304 in thumbnails
Diffstat (limited to 'src')
-rw-r--r--src/invidious.cr41
1 files changed, 30 insertions, 11 deletions
diff --git a/src/invidious.cr b/src/invidious.cr
index a5a5a229..5c809eab 100644
--- a/src/invidious.cr
+++ b/src/invidious.cr
@@ -3003,25 +3003,44 @@ 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"] = "*"
+ if response.status_code == 304
+ break
+ end
- begin
- chunk_size = 4096
- size = 1
- while size > 0
- size = IO.copy(response.body_io, env.response.output, chunk_size)
+ 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
- Fiber.yield
end
- rescue ex
- break
end
end
end