diff options
author | Jeremy Hylton <jeremy@alum.mit.edu> | 2002-07-07 16:57:35 (GMT) |
---|---|---|
committer | Jeremy Hylton <jeremy@alum.mit.edu> | 2002-07-07 16:57:35 (GMT) |
commit | 144dea3e05d82388c73011d66733726048765ebd (patch) | |
tree | 2b0ee7dffa7f13a6e65afb464ab5b2792da4d6b3 /Lib | |
parent | a6269a8ec5259aca453e8964464e2177d2a32fa2 (diff) | |
download | cpython-144dea3e05d82388c73011d66733726048765ebd.zip cpython-144dea3e05d82388c73011d66733726048765ebd.tar.gz cpython-144dea3e05d82388c73011d66733726048765ebd.tar.bz2 |
Fix from SF patch #527518: proxy config with user+pass authentication.
Bug fix candidate.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/urllib2.py | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/Lib/urllib2.py b/Lib/urllib2.py index 2c4a3e1..60c60d4 100644 --- a/Lib/urllib2.py +++ b/Lib/urllib2.py @@ -458,8 +458,11 @@ class ProxyHandler(BaseHandler): host, XXX = splithost(r_type) if '@' in host: user_pass, host = host.split('@', 1) - user_pass = base64.encodestring(unquote(user_pass)).strip() - req.add_header('Proxy-Authorization', 'Basic '+user_pass) + if ':' in user_pass: + user, password = user_pass.split(':', 1) + user_pass = base64.encodestring('%s:%s' % (unquote(user), + unquote(password))) + req.add_header('Proxy-Authorization', 'Basic ' + user_pass) host = unquote(host) req.set_proxy(host, type) if orig_type == type: @@ -764,7 +767,9 @@ class AbstractHTTPHandler(BaseHandler): except socket.error, err: raise URLError(err) - h.putheader('Host', host) + scheme, sel = splittype(req.get_selector()) + sel_host, sel_path = splithost(sel) + h.putheader('Host', sel_host or host) for args in self.parent.addheaders: h.putheader(*args) for k, v in req.headers.items(): |