@@ -163,6 +163,7 @@ def __init__(self, url, data=None, headers={},
163163 self .full_url = unwrap (url )
164164 self .data = data
165165 self .headers = {}
166+ self ._tunnel_host = None
166167 for key , value in headers .items ():
167168 self .add_header (key , value )
168169 self .unredirected_hdrs = {}
@@ -218,8 +219,12 @@ def get_origin_req_host(self):
218219 # End deprecated methods
219220
220221 def set_proxy (self , host , type ):
221- self .host , self .type = host , type
222- self .selector = self .full_url
222+ if self .type == 'https' and not self ._tunnel_host :
223+ self ._tunnel_host = self .host
224+ else :
225+ self .type = type
226+ self .selector = self .full_url
227+ self .host = host
223228
224229 def has_proxy (self ):
225230 return self .selector == self .full_url
@@ -659,7 +664,7 @@ def proxy_open(self, req, proxy, type):
659664 req .add_header ('Proxy-authorization' , 'Basic ' + creds )
660665 hostport = unquote (hostport )
661666 req .set_proxy (hostport , proxy_type )
662- if orig_type == proxy_type :
667+ if orig_type == proxy_type or orig_type == 'https' :
663668 # let other handlers take care of it
664669 return None
665670 else :
@@ -1041,6 +1046,10 @@ def do_open(self, http_class, req):
10411046 # request.
10421047 headers ["Connection" ] = "close"
10431048 headers = dict ((name .title (), val ) for name , val in headers .items ())
1049+
1050+ if req ._tunnel_host :
1051+ h .set_tunnel (req ._tunnel_host )
1052+
10441053 try :
10451054 h .request (req .get_method (), req .selector , req .data , headers )
10461055 r = h .getresponse () # an HTTPResponse instance
0 commit comments