Show More
@@ -2915,9 +2915,12 b' def debugwireproto(ui, repo, path=None, ' | |||||
2915 | raise error.Abort(_('--peer %s not supported with HTTP peers') % |
|
2915 | raise error.Abort(_('--peer %s not supported with HTTP peers') % | |
2916 | opts['peer']) |
|
2916 | opts['peer']) | |
2917 | else: |
|
2917 | else: | |
|
2918 | url, caps = httppeer.performhandshake(ui, url, opener, | |||
|
2919 | httppeer.urlreq.request) | |||
|
2920 | ||||
2918 | peer = httppeer.httppeer(ui, path, url, opener, |
|
2921 | peer = httppeer.httppeer(ui, path, url, opener, | |
2919 |
|
|
2922 | httppeer.urlreq.request, | |
2920 | peer._fetchcaps() |
|
2923 | caps) | |
2921 |
|
2924 | |||
2922 | # We /could/ populate stdin/stdout with sock.makefile()... |
|
2925 | # We /could/ populate stdin/stdout with sock.makefile()... | |
2923 | else: |
|
2926 | else: |
@@ -366,11 +366,11 b' def parsev1commandresponse(ui, baseurl, ' | |||||
366 | return respurl, resp |
|
366 | return respurl, resp | |
367 |
|
367 | |||
368 | class httppeer(wireproto.wirepeer): |
|
368 | class httppeer(wireproto.wirepeer): | |
369 | def __init__(self, ui, path, url, opener, requestbuilder): |
|
369 | def __init__(self, ui, path, url, opener, requestbuilder, caps): | |
370 | self.ui = ui |
|
370 | self.ui = ui | |
371 | self._path = path |
|
371 | self._path = path | |
372 | self._url = url |
|
372 | self._url = url | |
373 |
self._caps = |
|
373 | self._caps = caps | |
374 | self._urlopener = opener |
|
374 | self._urlopener = opener | |
375 | self._requestbuilder = requestbuilder |
|
375 | self._requestbuilder = requestbuilder | |
376 |
|
376 | |||
@@ -401,18 +401,12 b' class httppeer(wireproto.wirepeer):' | |||||
401 | # Begin of ipeercommands interface. |
|
401 | # Begin of ipeercommands interface. | |
402 |
|
402 | |||
403 | def capabilities(self): |
|
403 | def capabilities(self): | |
404 | # self._fetchcaps() should have been called as part of peer |
|
|||
405 | # handshake. So self._caps should always be set. |
|
|||
406 | assert self._caps is not None |
|
|||
407 | return self._caps |
|
404 | return self._caps | |
408 |
|
405 | |||
409 | # End of ipeercommands interface. |
|
406 | # End of ipeercommands interface. | |
410 |
|
407 | |||
411 | # look up capabilities only when needed |
|
408 | # look up capabilities only when needed | |
412 |
|
409 | |||
413 | def _fetchcaps(self): |
|
|||
414 | self._caps = set(self._call('capabilities').split()) |
|
|||
415 |
|
||||
416 | def _callstream(self, cmd, _compressible=False, **args): |
|
410 | def _callstream(self, cmd, _compressible=False, **args): | |
417 | args = pycompat.byteskwargs(args) |
|
411 | args = pycompat.byteskwargs(args) | |
418 |
|
412 | |||
@@ -603,6 +597,29 b' class httpv2peer(object):' | |||||
603 |
|
597 | |||
604 | return results |
|
598 | return results | |
605 |
|
599 | |||
|
600 | def performhandshake(ui, url, opener, requestbuilder): | |||
|
601 | # The handshake is a request to the capabilities command. | |||
|
602 | ||||
|
603 | caps = None | |||
|
604 | def capable(x): | |||
|
605 | raise error.ProgrammingError('should not be called') | |||
|
606 | ||||
|
607 | req, requrl, qs = makev1commandrequest(ui, requestbuilder, caps, | |||
|
608 | capable, url, 'capabilities', | |||
|
609 | {}) | |||
|
610 | ||||
|
611 | resp = sendrequest(ui, opener, req) | |||
|
612 | ||||
|
613 | respurl, resp = parsev1commandresponse(ui, url, requrl, qs, resp, | |||
|
614 | compressible=False) | |||
|
615 | ||||
|
616 | try: | |||
|
617 | rawcaps = resp.read() | |||
|
618 | finally: | |||
|
619 | resp.close() | |||
|
620 | ||||
|
621 | return respurl, set(rawcaps.split()) | |||
|
622 | ||||
606 | def makepeer(ui, path, requestbuilder=urlreq.request): |
|
623 | def makepeer(ui, path, requestbuilder=urlreq.request): | |
607 | """Construct an appropriate HTTP peer instance. |
|
624 | """Construct an appropriate HTTP peer instance. | |
608 |
|
625 | |||
@@ -620,7 +637,9 b' def makepeer(ui, path, requestbuilder=ur' | |||||
620 |
|
637 | |||
621 | opener = urlmod.opener(ui, authinfo) |
|
638 | opener = urlmod.opener(ui, authinfo) | |
622 |
|
639 | |||
623 |
re |
|
640 | respurl, caps = performhandshake(ui, url, opener, requestbuilder) | |
|
641 | ||||
|
642 | return httppeer(ui, path, respurl, opener, requestbuilder, caps) | |||
624 |
|
643 | |||
625 | def instance(ui, path, create): |
|
644 | def instance(ui, path, create): | |
626 | if create: |
|
645 | if create: | |
@@ -631,7 +650,6 b' def instance(ui, path, create):' | |||||
631 | 'is not installed')) |
|
650 | 'is not installed')) | |
632 |
|
651 | |||
633 | inst = makepeer(ui, path) |
|
652 | inst = makepeer(ui, path) | |
634 | inst._fetchcaps() |
|
|||
635 |
|
653 | |||
636 | return inst |
|
654 | return inst | |
637 | except error.RepoError as httpexception: |
|
655 | except error.RepoError as httpexception: |
@@ -67,10 +67,11 b' class dummyrepo(object):' | |||||
67 | class dummyopener(object): |
|
67 | class dummyopener(object): | |
68 | handlers = [] |
|
68 | handlers = [] | |
69 |
|
69 | |||
70 |
# Facilitates testing sshpeer without requiring a |
|
70 | # Facilitates testing sshpeer without requiring a server. | |
71 | class badpeer(httppeer.httppeer): |
|
71 | class badpeer(httppeer.httppeer): | |
72 | def __init__(self): |
|
72 | def __init__(self): | |
73 |
super(badpeer, self).__init__(None, None, None, dummyopener(), None |
|
73 | super(badpeer, self).__init__(None, None, None, dummyopener(), None, | |
|
74 | None) | |||
74 | self.badattribute = True |
|
75 | self.badattribute = True | |
75 |
|
76 | |||
76 | def badmethod(self): |
|
77 | def badmethod(self): | |
@@ -89,7 +90,7 b' def main():' | |||||
89 |
|
90 | |||
90 | ziverify.verifyClass(repository.ipeerbaselegacycommands, |
|
91 | ziverify.verifyClass(repository.ipeerbaselegacycommands, | |
91 | httppeer.httppeer) |
|
92 | httppeer.httppeer) | |
92 | checkzobject(httppeer.httppeer(None, None, None, dummyopener(), None)) |
|
93 | checkzobject(httppeer.httppeer(None, None, None, dummyopener(), None, None)) | |
93 |
|
94 | |||
94 | ziverify.verifyClass(repository.ipeerbase, |
|
95 | ziverify.verifyClass(repository.ipeerbase, | |
95 | localrepo.localpeer) |
|
96 | localrepo.localpeer) |
General Comments 0
You need to be logged in to leave comments.
Login now