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 |
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 |