From: Johannes Knoedtel Date: Mon, 12 Jan 2015 21:26:20 +0000 (+0100) Subject: [utils] Prevent override of custom headers. X-Git-Url: http://git.oshgnacknak.de/?a=commitdiff_plain;h=3d5f7a3947a8d304bc7ad46217f171996e95c475;p=youtube-dl [utils] Prevent override of custom headers. The dict of headers of request objects in urllib has its keys always capitalized. This causes the lookup to fail and overwrite the header. If for example a Extractor tries to add a "User-Agent" header the internal representation in the request object is "User-agent". The header is therefore clobbered by the "User-Agent" in std_headers, because the strings are not equal. --- diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index 98732e8e9..daf94abd1 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -611,7 +611,9 @@ class YoutubeDLHandler(compat_urllib_request.HTTPHandler): def http_request(self, req): for h, v in std_headers.items(): - if h not in req.headers: + # Capitalize is needed because of Python bug 2275: http://bugs.python.org/issue2275 + # 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: