aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/utils.py
diff options
context:
space:
mode:
authorPhilipp Hagemeister <phihag@phihag.de>2015-03-03 13:56:06 +0100
committerPhilipp Hagemeister <phihag@phihag.de>2015-03-03 13:56:06 +0100
commit2461f79d2ad9eee44644f6187e366125a29aa70f (patch)
tree9c8490ac92b196f1d9feb5a49b4d6d31809c2879 /youtube_dl/utils.py
parent91410c9bfa9fd8f01fb817474bcc7b0db5cabf95 (diff)
[utils] Correct per-request proxy handling
Diffstat (limited to 'youtube_dl/utils.py')
-rw-r--r--youtube_dl/utils.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py
index b568288fa..7426e2a1f 100644
--- a/youtube_dl/utils.py
+++ b/youtube_dl/utils.py
@@ -1771,10 +1771,21 @@ def match_filter_func(filter_str):
class PerRequestProxyHandler(compat_urllib_request.ProxyHandler):
+ def __init__(self, proxies=None):
+ # Set default handlers
+ for type in ('http', 'https'):
+ setattr(self, '%s_open' % type,
+ lambda r, proxy='__noproxy__', type=type, meth=self.proxy_open:
+ meth(r, proxy, type))
+ return compat_urllib_request.ProxyHandler.__init__(self, proxies)
+
def proxy_open(self, req, proxy, type):
- req_proxy = req.headers.get('Ytdl-Request-Proxy')
+ req_proxy = req.headers.get('Ytdl-request-proxy')
if req_proxy is not None:
proxy = req_proxy
- del req.headers['Ytdl-Request-Proxy']
+ del req.headers['Ytdl-request-proxy']
+
+ if proxy == '__noproxy__':
+ return None # No Proxy
return compat_urllib_request.ProxyHandler.proxy_open(
self, req, proxy, type)