mercurial/httppeer.py
changeset 49871 cfe8d88a453e
parent 49869 5f71fff8dc74
child 50458 ed052780ad5e
equal deleted inserted replaced
49870:20f262ab6fd3 49871:cfe8d88a453e
   380     return respurl, proto, resp
   380     return respurl, proto, resp
   381 
   381 
   382 
   382 
   383 class httppeer(wireprotov1peer.wirepeer):
   383 class httppeer(wireprotov1peer.wirepeer):
   384     def __init__(self, ui, path, url, opener, requestbuilder, caps):
   384     def __init__(self, ui, path, url, opener, requestbuilder, caps):
   385         super().__init__(ui)
   385         super().__init__(ui, path=path)
   386         self._path = path
       
   387         self._url = url
   386         self._url = url
   388         self._caps = caps
   387         self._caps = caps
   389         self.limitedarguments = caps is not None and b'httppostargs' not in caps
   388         self.limitedarguments = caps is not None and b'httppostargs' not in caps
   390         self._urlopener = opener
   389         self._urlopener = opener
   391         self._requestbuilder = requestbuilder
   390         self._requestbuilder = requestbuilder
   396             getattr(h, "close_all", lambda: None)()
   395             getattr(h, "close_all", lambda: None)()
   397 
   396 
   398     # Begin of ipeerconnection interface.
   397     # Begin of ipeerconnection interface.
   399 
   398 
   400     def url(self):
   399     def url(self):
   401         return self._path
   400         return self.path.loc
   402 
   401 
   403     def local(self):
   402     def local(self):
   404         return None
   403         return None
   405 
   404 
   406     def canpush(self):
   405     def canpush(self):
   600     connections, perform HTTP requests.
   599     connections, perform HTTP requests.
   601 
   600 
   602     ``requestbuilder`` is the type used for constructing HTTP requests.
   601     ``requestbuilder`` is the type used for constructing HTTP requests.
   603     It exists as an argument so extensions can override the default.
   602     It exists as an argument so extensions can override the default.
   604     """
   603     """
   605     u = urlutil.url(path)
   604     if path.url.query or path.url.fragment:
   606     if u.query or u.fragment:
   605         msg = _(b'unsupported URL component: "%s"')
   607         raise error.Abort(
   606         msg %= path.url.query or path.url.fragment
   608             _(b'unsupported URL component: "%s"') % (u.query or u.fragment)
   607         raise error.Abort(msg)
   609         )
       
   610 
   608 
   611     # urllib cannot handle URLs with embedded user or passwd.
   609     # urllib cannot handle URLs with embedded user or passwd.
   612     url, authinfo = u.authinfo()
   610     url, authinfo = path.url.authinfo()
   613     ui.debug(b'using %s\n' % url)
   611     ui.debug(b'using %s\n' % url)
   614 
   612 
   615     opener = opener or urlmod.opener(ui, authinfo)
   613     opener = opener or urlmod.opener(ui, authinfo)
   616 
   614 
   617     respurl, info = performhandshake(ui, url, opener, requestbuilder)
   615     respurl, info = performhandshake(ui, url, opener, requestbuilder)
   622 
   620 
   623 
   621 
   624 def make_peer(ui, path, create, intents=None, createopts=None):
   622 def make_peer(ui, path, create, intents=None, createopts=None):
   625     if create:
   623     if create:
   626         raise error.Abort(_(b'cannot create new http repository'))
   624         raise error.Abort(_(b'cannot create new http repository'))
   627     path = path.loc
       
   628     try:
   625     try:
   629         if path.startswith(b'https:') and not urlmod.has_https:
   626         if path.url.scheme == b'https' and not urlmod.has_https:
   630             raise error.Abort(
   627             raise error.Abort(
   631                 _(b'Python support for SSL and HTTPS is not installed')
   628                 _(b'Python support for SSL and HTTPS is not installed')
   632             )
   629             )
   633 
   630 
   634         inst = makepeer(ui, path)
   631         inst = makepeer(ui, path)
   635 
   632 
   636         return inst
   633         return inst
   637     except error.RepoError as httpexception:
   634     except error.RepoError as httpexception:
   638         try:
   635         try:
   639             r = statichttprepo.make_peer(ui, b"static-" + path, create)
   636             r = statichttprepo.make_peer(ui, b"static-" + path.loc, create)
   640             ui.note(_(b'(falling back to static-http)\n'))
   637             ui.note(_(b'(falling back to static-http)\n'))
   641             return r
   638             return r
   642         except error.RepoError:
   639         except error.RepoError:
   643             raise httpexception  # use the original http RepoError instead
   640             raise httpexception  # use the original http RepoError instead