diff options
author | coletdjnz <coletdjnz@protonmail.com> | 2023-05-21 10:55:09 +1200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-20 22:55:09 +0000 |
commit | 955c89584b66fcd0fcfab3e611f1edeb1ca63886 (patch) | |
tree | 34e055368b414b5cc908e84e97a7823f27f1d7c3 /yt_dlp/utils/_utils.py | |
parent | 69bec6730ec9d724bcedeab199d9d684d61423ba (diff) | |
download | hypervideo-pre-955c89584b66fcd0fcfab3e611f1edeb1ca63886.tar.lz hypervideo-pre-955c89584b66fcd0fcfab3e611f1edeb1ca63886.tar.xz hypervideo-pre-955c89584b66fcd0fcfab3e611f1edeb1ca63886.zip |
[core] Deprecate internal `Youtubedl-no-compression` header (#6876)
Authored by: coletdjnz
Diffstat (limited to 'yt_dlp/utils/_utils.py')
-rw-r--r-- | yt_dlp/utils/_utils.py | 23 |
1 files changed, 6 insertions, 17 deletions
diff --git a/yt_dlp/utils/_utils.py b/yt_dlp/utils/_utils.py index f032af901..9f1a127cd 100644 --- a/yt_dlp/utils/_utils.py +++ b/yt_dlp/utils/_utils.py @@ -1308,25 +1308,12 @@ def _create_http_connection(ydl_handler, http_class, is_https, *args, **kwargs): return hc -def handle_youtubedl_headers(headers): - filtered_headers = headers - - if 'Youtubedl-no-compression' in filtered_headers: - filtered_headers = {k: v for k, v in filtered_headers.items() if k.lower() != 'accept-encoding'} - del filtered_headers['Youtubedl-no-compression'] - - return filtered_headers - - class YoutubeDLHandler(urllib.request.HTTPHandler): """Handler for HTTP requests and responses. This class, when installed with an OpenerDirector, automatically adds - the standard headers to every HTTP request and handles gzipped and - deflated responses from web servers. If compression is to be avoided in - a particular request, the original request in the program code only has - to include the HTTP header "Youtubedl-no-compression", which will be - removed before making the real request. + the standard headers to every HTTP request and handles gzipped, deflated and + brotli responses from web servers. Part of this code was copied from: @@ -1389,11 +1376,13 @@ class YoutubeDLHandler(urllib.request.HTTPHandler): if h.capitalize() not in req.headers: req.add_header(h, v) + if 'Youtubedl-no-compression' in req.headers: # deprecated + req.headers.pop('Youtubedl-no-compression', None) + req.add_header('Accept-encoding', 'identity') + if 'Accept-encoding' not in req.headers: req.add_header('Accept-encoding', ', '.join(SUPPORTED_ENCODINGS)) - req.headers = handle_youtubedl_headers(req.headers) - return super().do_request_(req) def http_response(self, req, resp): |