[utils] Advertise optional supported `Content-Encoding`s
authordirkf <fieldhouse@gmx.net>
Sun, 30 Jul 2023 20:50:52 +0000 (21:50 +0100)
committerdirkf <fieldhouse@gmx.net>
Tue, 1 Aug 2023 00:05:09 +0000 (01:05 +0100)
youtube_dl/utils.py

index c530ed5a2df93c8ca834458d41ef5c7367965518..81ff788079a1087baec8f8d1f44dca44c3525836 100644 (file)
@@ -1678,9 +1678,7 @@ def random_user_agent():
 
 std_headers = {
     'User-Agent': random_user_agent(),
-    'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
     'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
-    'Accept-Encoding': 'gzip, deflate',
     'Accept-Language': 'en-us,en;q=0.5',
 }
 
@@ -2724,6 +2722,13 @@ class YoutubeDLHandler(compat_urllib_request.HTTPHandler):
             if h.capitalize() not in req.headers:
                 req.add_header(h, v)
 
+        # Similarly, 'Accept-encoding'
+        if 'Accept-encoding' not in req.headers:
+            req.add_header(
+                'Accept-Encoding', join_nonempty(
+                    'gzip', 'deflate', brotli and 'br', ncompress and 'compress',
+                    delim=', '))
+
         req.headers = handle_youtubedl_headers(req.headers)
 
         if sys.version_info < (2, 7):