summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorÉmilien Devos <contact@emiliendevos.be>2021-11-28 08:41:16 +0000
committerGitHub <noreply@github.com>2021-11-28 09:41:16 +0100
commitc6e086c6fff9699a32465da0ce5e4784c981e886 (patch)
tree871e1691a6e7b1ce18969d17951ad153a310cece /src
parent82f3eda82b9e97a94f98e6f325b428d985d9852d (diff)
downloadinvidious-c6e086c6fff9699a32465da0ce5e4784c981e886.tar.gz
invidious-c6e086c6fff9699a32465da0ce5e4784c981e886.tar.bz2
invidious-c6e086c6fff9699a32465da0ce5e4784c981e886.zip
Revert "Temporarily fix for #2612" (#2673)
Diffstat (limited to 'src')
-rw-r--r--src/invidious/yt_backend/youtube_api.cr45
1 files changed, 12 insertions, 33 deletions
diff --git a/src/invidious/yt_backend/youtube_api.cr b/src/invidious/yt_backend/youtube_api.cr
index 977aea04..27f25036 100644
--- a/src/invidious/yt_backend/youtube_api.cr
+++ b/src/invidious/yt_backend/youtube_api.cr
@@ -404,10 +404,19 @@ module YoutubeAPI
url = "#{endpoint}?key=#{client_config.api_key}"
headers = HTTP::Headers{
- "Content-Type" => "application/json; charset=UTF-8",
- "Accept-Encoding" => "gzip, deflate",
+ "Content-Type" => "application/json; charset=UTF-8",
}
+ # The normal HTTP client automatically applies accept-encoding: gzip,
+ # and decompresses. However, explicitly applying it will remove this functionality.
+ #
+ # https://github.com/crystal-lang/crystal/issues/11252#issuecomment-929594741
+ {% unless flag?(:disable_quic) %}
+ if CONFIG.use_quic
+ headers["Accept-Encoding"] = "gzip"
+ end
+ {% end %}
+
# Logging
LOGGER.debug("YoutubeAPI: Using endpoint: \"#{endpoint}\"")
LOGGER.trace("YoutubeAPI: ClientConfig: #{client_config}")
@@ -425,38 +434,8 @@ module YoutubeAPI
)
end
- if {{ !flag?(:disable_quic) }} && CONFIG.use_quic
- body = response.body
- else
- # Decompress the body ourselves, when using HTTP::Client given that
- # auto-decompress is broken in the Crystal stdlib.
- # Read more:
- # - https://github.com/iv-org/invidious/issues/2612
- # - https://github.com/crystal-lang/crystal/issues/11354
- #
- if encodings = response.headers["Content-Encoding"]?
- io = response.body_io
-
- # Multiple encodings can be combined, and are listed in the order
- # in which they were applied. E.g: "deflate, gzip" means that the
- # content must be first "gunzipped", then "defated".
- encodings.split(',').reverse.each do |enc|
- case enc.strip(' ')
- when "gzip"
- io = Compress::Gzip::Reader.new(io, sync_close: true)
- when "deflate"
- io = Compress::Deflate::Reader.new(io, sync_close: true)
- end
- end
-
- body = io.gets_to_end
- else
- body = response.body
- end
- end
-
# Convert result to Hash
- initial_data = JSON.parse(body).as_h
+ initial_data = JSON.parse(response.body).as_h
# Error handling
if initial_data.has_key?("error")