]> granicus.if.org Git - python/commitdiff
Fix from SF patch #527518: proxy config with user+pass authentication.
authorJeremy Hylton <jeremy@alum.mit.edu>
Sun, 7 Jul 2002 16:57:35 +0000 (16:57 +0000)
committerJeremy Hylton <jeremy@alum.mit.edu>
Sun, 7 Jul 2002 16:57:35 +0000 (16:57 +0000)
Bug fix candidate.

Lib/urllib2.py

index 2c4a3e109f4f327295e66a2c34ed281808f8b79d..60c60d4eed685490e80dd5a3b27fa70053f03764 100644 (file)
@@ -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():