From e7926ae9f4e5fa258696551a39295402819280c9 Mon Sep 17 00:00:00 2001 From: dirkf Date: Fri, 28 Jul 2023 06:03:14 +0100 Subject: [PATCH] [utils] Rework decoding of `Content-Encoding`s * support nested encodings * support optional `br` encoding, if brotli package is installed * support optional 'compress' encoding, if ncompress package is installed * response `Content-Encoding` has only unprocessed encodings, or removed * response `Content-Length` is decoded length (usable for filesize metadata) * use zlib for both deflate and gzip decompression * some elements taken from yt-dlp: thx especially coletdjnz --- test/test_http.py | 16 ++---- youtube_dl/compat.py | 14 +++++ youtube_dl/utils.py | 120 ++++++++++++++++++++++++++++++++----------- 3 files changed, 107 insertions(+), 43 deletions(-) diff --git a/test/test_http.py b/test/test_http.py index 89580969d..793bea359 100644 --- a/test/test_http.py +++ b/test/test_http.py @@ -461,33 +461,23 @@ class TestHTTP(unittest.TestCase): sanitized_Request( self._test_url('content-encoding'), headers={'ytdl-encoding': encoding})) - self.assertEqual(res.headers.get('Content-Encoding'), encoding) + # decoded encodings are removed: only check for valid decompressed data self.assertEqual(res.read(), b'