@@ -458,8 +458,11 @@ def proxy_open(self, req, proxy, type):
458458 host , XXX = splithost (r_type )
459459 if '@' in host :
460460 user_pass , host = host .split ('@' , 1 )
461- user_pass = base64 .encodestring (unquote (user_pass )).strip ()
462- req .add_header ('Proxy-Authorization' , 'Basic ' + user_pass )
461+ if ':' in user_pass :
462+ user , password = user_pass .split (':' , 1 )
463+ user_pass = base64 .encodestring ('%s:%s' % (unquote (user ),
464+ unquote (password )))
465+ req .add_header ('Proxy-Authorization' , 'Basic ' + user_pass )
463466 host = unquote (host )
464467 req .set_proxy (host , type )
465468 if orig_type == type :
@@ -764,7 +767,9 @@ def do_open(self, http_class, req):
764767 except socket .error , err :
765768 raise URLError (err )
766769
767- h .putheader ('Host' , host )
770+ scheme , sel = splittype (req .get_selector ())
771+ sel_host , sel_path = splithost (sel )
772+ h .putheader ('Host' , sel_host or host )
768773 for args in self .parent .addheaders :
769774 h .putheader (* args )
770775 for k , v in req .headers .items ():
0 commit comments