@@ -477,8 +477,8 @@ def proxy_open(self, req, proxy, type):
477477 host , XXX = splithost (r_type )
478478 if '@' in host :
479479 user_pass , host = host .split ('@' , 1 )
480- user_pass = base64 .encode_string (unquote (user_passw )).strip ()
481- req .addheader ('Proxy-Authorization' , user_pass )
480+ user_pass = base64 .encodestring (unquote (user_pass )).strip ()
481+ req .add_header ('Proxy-Authorization' , 'Basic ' + user_pass )
482482 host = unquote (host )
483483 req .set_proxy (host , type )
484484 if orig_type == type :
@@ -781,7 +781,7 @@ def encode_digest(digest):
781781class AbstractHTTPHandler (BaseHandler ):
782782
783783 def do_open (self , http_class , req ):
784- host = req .get_host ()
784+ host = urlparse . urlparse ( req .get_full_url ())[ 1 ]
785785 if not host :
786786 raise URLError ('no host given' )
787787
@@ -790,15 +790,16 @@ def do_open(self, http_class, req):
790790 if req .has_data ():
791791 data = req .get_data ()
792792 h .putrequest ('POST' , req .get_selector ())
793- h .putheader ('Content-type' ,
794- 'application/x-www-form-urlencoded' )
795- h .putheader ('Content-length' , '%d' % len (data ))
793+ if not req .headers .has_key ('Content-type' ):
794+ h .putheader ('Content-type' ,
795+ 'application/x-www-form-urlencoded' )
796+ if not req .headers .has_key ('Content-length' ):
797+ h .putheader ('Content-length' , '%d' % len (data ))
796798 else :
797799 h .putrequest ('GET' , req .get_selector ())
798800 except socket .error , err :
799801 raise URLError (err )
800802
801- # XXX proxies would have different host here
802803 h .putheader ('Host' , host )
803804 for args in self .parent .addheaders :
804805 h .putheader (* args )
0 commit comments