]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
backport jhylton's checkin of
authorMichael W. Hudson <mwh@python.net>
Wed, 25 Sep 2002 10:32:49 +0000 (10:32 +0000)
committerMichael W. Hudson <mwh@python.net>
Wed, 25 Sep 2002 10:32:49 +0000 (10:32 +0000)
    revision 1.32 of urllib2.py

Fix from SF patch #527518: proxy config with user+pass authentication.

Bug fix candidate.

Lib/urllib2.py

index 512d90c060449c28abb78e722c822b55a4e244b0..e9f2d52a9ed1b284a6d575c189ef9b4fe194cb08 100644 (file)
@@ -456,8 +456,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:
@@ -762,7 +765,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():