diff options
| author | Samantaz Fox <coding@samantaz.fr> | 2021-11-21 18:16:05 +0100 |
|---|---|---|
| committer | Samantaz Fox <coding@samantaz.fr> | 2021-11-21 18:16:05 +0100 |
| commit | ba48f68fc30990437331791848efe896559f49cd (patch) | |
| tree | 640aa3642d9a5286bde95dc7362cb67659f4fd3b | |
| parent | 2c447a42f29a05b8067444338248e344b3705cd0 (diff) | |
| download | invidious-ba48f68fc30990437331791848efe896559f49cd.tar.gz invidious-ba48f68fc30990437331791848efe896559f49cd.tar.bz2 invidious-ba48f68fc30990437331791848efe896559f49cd.zip | |
allow multiple, successive content-encodings
| -rw-r--r-- | src/invidious/yt_backend/youtube_api.cr | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/invidious/yt_backend/youtube_api.cr b/src/invidious/yt_backend/youtube_api.cr index b26af8d1..977aea04 100644 --- a/src/invidious/yt_backend/youtube_api.cr +++ b/src/invidious/yt_backend/youtube_api.cr @@ -434,11 +434,22 @@ module YoutubeAPI # - https://github.com/iv-org/invidious/issues/2612 # - https://github.com/crystal-lang/crystal/issues/11354 # - case response.headers["Content-Encoding"]? - when "gzip" - body = Compress::Gzip::Reader.new(response.body_io, sync_close: true) - when "deflate" - body = Compress::Deflate::Reader.new(response.body_io, sync_close: true) + 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 |
