diff options
author | Yen Chi Hsuan <yan12125@gmail.com> | 2015-11-29 12:42:50 +0800 |
---|---|---|
committer | Yen Chi Hsuan <yan12125@gmail.com> | 2015-11-29 12:42:50 +0800 |
commit | 87f0e62d94e0486598d123e26db3173e6f1d18e6 (patch) | |
tree | 170ad1517b0cc538b0902ab199b099dec4cb0ba6 | |
parent | 46b4070f3f8cbe2b66baadb2927eba03fbdd1129 (diff) |
[utils] Separate codes for handling Youtubedl-* headers
-rw-r--r-- | youtube_dl/utils.py | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index d7b737e21..653a49055 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -663,6 +663,15 @@ def _create_http_connection(ydl_handler, http_class, is_https, *args, **kwargs): return hc +def handle_youtubedl_headers(headers): + if 'Youtubedl-no-compression' in headers: + filtered_headers = dict((k, v) for k, v in headers.items() if k.lower() != 'accept-encoding') + del filtered_headers['Youtubedl-no-compression'] + return filtered_headers + + return headers + + class YoutubeDLHandler(compat_urllib_request.HTTPHandler): """Handler for HTTP requests and responses. @@ -731,10 +740,8 @@ class YoutubeDLHandler(compat_urllib_request.HTTPHandler): # The dict keys are capitalized because of this bug by urllib if h.capitalize() not in req.headers: req.add_header(h, v) - if 'Youtubedl-no-compression' in req.headers: - if 'Accept-encoding' in req.headers: - del req.headers['Accept-encoding'] - del req.headers['Youtubedl-no-compression'] + + req.headers = handle_youtubedl_headers(req.headers) if sys.version_info < (2, 7) and '#' in req.get_full_url(): # Python 2.6 is brain-dead when it comes to fragments |