mercurial/httpconnection.py
changeset 34466 1232f7fa00c3
parent 33499 0407a51b9d8c
child 35358 8549ca7fcde1
equal deleted inserted replaced
34465:80d4681150b9 34466:1232f7fa00c3
    16 
    16 
    17 from .i18n import _
    17 from .i18n import _
    18 from . import (
    18 from . import (
    19     httpclient,
    19     httpclient,
    20     sslutil,
    20     sslutil,
       
    21     urllibcompat,
    21     util,
    22     util,
    22 )
    23 )
    23 
    24 
    24 urlerr = util.urlerr
    25 urlerr = util.urlerr
    25 urlreq = util.urlreq
    26 urlreq = util.urlreq
   172         # actually the proxy. On Python 2.6.1, the real destination
   173         # actually the proxy. On Python 2.6.1, the real destination
   173         # hostname is encoded in the URI in the urllib2 request
   174         # hostname is encoded in the URI in the urllib2 request
   174         # object. On Python 2.6.5, it's stored in the _tunnel_host
   175         # object. On Python 2.6.5, it's stored in the _tunnel_host
   175         # attribute which has no accessor.
   176         # attribute which has no accessor.
   176         tunhost = getattr(req, '_tunnel_host', None)
   177         tunhost = getattr(req, '_tunnel_host', None)
   177         host = req.get_host()
   178         host = urllibcompat.gethost(req)
   178         if tunhost:
   179         if tunhost:
   179             proxyhost = host
   180             proxyhost = host
   180             host = tunhost
   181             host = tunhost
   181         elif req.has_proxy():
   182         elif req.has_proxy():
   182             proxyhost = req.get_host()
   183             proxyhost = urllibcompat.gethost(req)
   183             host = req.get_selector().split('://', 1)[1].split('/', 1)[0]
   184             host = urllibcompat.getselector(
       
   185                 req).split('://', 1)[1].split('/', 1)[0]
   184         else:
   186         else:
   185             proxyhost = None
   187             proxyhost = None
   186 
   188 
   187         if proxyhost:
   189         if proxyhost:
   188             if ':' in proxyhost:
   190             if ':' in proxyhost:
   217         headers = dict(req.headers)
   219         headers = dict(req.headers)
   218         headers.update(req.unredirected_hdrs)
   220         headers.update(req.unredirected_hdrs)
   219         headers = dict(
   221         headers = dict(
   220             (name.title(), val) for name, val in headers.items())
   222             (name.title(), val) for name, val in headers.items())
   221         try:
   223         try:
   222             path = req.get_selector()
   224             path = urllibcompat.getselector(req)
   223             if '://' in path:
   225             if '://' in path:
   224                 path = path.split('://', 1)[1].split('/', 1)[1]
   226                 path = path.split('://', 1)[1].split('/', 1)[1]
   225             if path[0] != '/':
   227             if path[0] != '/':
   226                 path = '/' + path
   228                 path = '/' + path
   227             h.request(req.get_method(), path, req.data, headers)
   229             h.request(req.get_method(), path, req.data, headers)
   231 
   233 
   232         # Pick apart the HTTPResponse object to get the addinfourl
   234         # Pick apart the HTTPResponse object to get the addinfourl
   233         # object initialized properly.
   235         # object initialized properly.
   234         r.recv = r.read
   236         r.recv = r.read
   235 
   237 
   236         resp = urlreq.addinfourl(r, r.headers, req.get_full_url())
   238         resp = urlreq.addinfourl(r, r.headers, urllibcompat.getfullurl(req))
   237         resp.code = r.status
   239         resp.code = r.status
   238         resp.msg = r.reason
   240         resp.msg = r.reason
   239         return resp
   241         return resp
   240 
   242 
   241     # httplib always uses the given host/port as the socket connect
   243     # httplib always uses the given host/port as the socket connect
   242     # target, and then allows full URIs in the request path, which it
   244     # target, and then allows full URIs in the request path, which it
   243     # then observes and treats as a signal to do proxying instead.
   245     # then observes and treats as a signal to do proxying instead.
   244     def http_open(self, req):
   246     def http_open(self, req):
   245         if req.get_full_url().startswith('https'):
   247         if urllibcompat.getfullurl(req).startswith('https'):
   246             return self.https_open(req)
   248             return self.https_open(req)
   247         def makehttpcon(*args, **kwargs):
   249         def makehttpcon(*args, **kwargs):
   248             k2 = dict(kwargs)
   250             k2 = dict(kwargs)
   249             k2['use_ssl'] = False
   251             k2['use_ssl'] = False
   250             return HTTPConnection(*args, **k2)
   252             return HTTPConnection(*args, **k2)
   251         return self.do_open(makehttpcon, req, False)
   253         return self.do_open(makehttpcon, req, False)
   252 
   254 
   253     def https_open(self, req):
   255     def https_open(self, req):
   254         # req.get_full_url() does not contain credentials and we may
   256         # urllibcompat.getfullurl(req) does not contain credentials and we may
   255         # need them to match the certificates.
   257         # need them to match the certificates.
   256         url = req.get_full_url()
   258         url = urllibcompat.getfullurl(req)
   257         user, password = self.pwmgr.find_stored_password(url)
   259         user, password = self.pwmgr.find_stored_password(url)
   258         res = readauthforuri(self.ui, url, user)
   260         res = readauthforuri(self.ui, url, user)
   259         if res:
   261         if res:
   260             group, auth = res
   262             group, auth = res
   261             self.auth = auth
   263             self.auth = auth