about summary refs log tree commit diff
path: root/test
diff options
context:
space:
mode:
authordirkf <fieldhouse@gmx.net>2023-07-28 06:03:14 +0100
committerdirkf <fieldhouse@gmx.net>2023-07-29 14:27:26 +0100
commite7926ae9f4e5fa258696551a39295402819280c9 (patch)
tree979a70febc93910d6854077b8efc913aee5eca22 /test
parent87e578c9b891b29ab6559ac81ed391897b1e1ace (diff)
downloadyoutube-dl-e7926ae9f4e5fa258696551a39295402819280c9.tar.gz
youtube-dl-e7926ae9f4e5fa258696551a39295402819280c9.tar.xz
youtube-dl-e7926ae9f4e5fa258696551a39295402819280c9.zip
[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
Diffstat (limited to 'test')
-rw-r--r--test/test_http.py16
1 files changed, 3 insertions, 13 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'<html><video src="/vid.mp4" /></html>')
 
     @unittest.skipUnless(brotli, 'brotli support is not installed')
-    @unittest.expectedFailure
     def test_brotli(self):
         self.__test_compression('br')
 
-    @unittest.expectedFailure
     def test_deflate(self):
         self.__test_compression('deflate')
 
-    @unittest.expectedFailure
     def test_gzip(self):
         self.__test_compression('gzip')
 
-    @unittest.expectedFailure  # not yet implemented
     def test_multiple_encodings(self):
         # https://www.rfc-editor.org/rfc/rfc9110.html#section-8.4
-        with FakeYDL() as ydl:
-            for pair in ('gzip,deflate', 'deflate, gzip', 'gzip, gzip', 'deflate, deflate'):
-                res = ydl.urlopen(
-                    sanitized_Request(
-                        self._test_url('content-encoding'),
-                        headers={'ytdl-encoding': pair}))
-                self.assertEqual(res.headers.get('Content-Encoding'), pair)
-                self.assertEqual(res.read(), b'<html><video src="/vid.mp4" /></html>')
+        for pair in ('gzip,deflate', 'deflate, gzip', 'gzip, gzip', 'deflate, deflate'):
+            self.__test_compression(pair)
 
     def test_unsupported_encoding(self):
         # it should return the raw content