From b0f127d4d89bc1a001c9ad37b27eec8d9d8e7961 Mon Sep 17 00:00:00 2001 From: syeopite Date: Tue, 28 Sep 2021 14:57:48 -0700 Subject: [PATCH] Fix gzip decompression with HTTP::Client --- src/invidious/yt_backend/youtube_api.cr | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/invidious/yt_backend/youtube_api.cr b/src/invidious/yt_backend/youtube_api.cr index 8ab2fe46..8904b589 100644 --- a/src/invidious/yt_backend/youtube_api.cr +++ b/src/invidious/yt_backend/youtube_api.cr @@ -404,10 +404,17 @@ module YoutubeAPI url = "#{endpoint}?key=#{client_config.api_key}" headers = HTTP::Headers{ - "Content-Type" => "application/json; charset=UTF-8", - "Accept-Encoding" => "gzip", + "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) %} + headers["Accept-Encoding"] = "gzip" + {% end %} + # Logging LOGGER.debug("YoutubeAPI: Using endpoint: \"#{endpoint}\"") LOGGER.trace("YoutubeAPI: ClientConfig: #{client_config}")