Mercurial > public > mercurial-scm > hg
comparison mercurial/httppeer.py @ 37546:3a2367e6c6f2
wireproto: move version 2 command handlers to wireprotov2server
This is relatively straightforward.
As part of this, we introduced a local @wireprotocommand that
wraps the main one and defines a v2 only policy by default.
Because the hacky HTTPv2 peer isn't using capabilities response
yet, we had to move some code around to force import of
wireprotov2server so commands are registered. This is super
hacky. But this code will go away once the HTTPv2 peer is using
the capabilities response to derive permissions.
Differential Revision: https://phab.mercurial-scm.org/D3231
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Mon, 09 Apr 2018 19:35:39 -0700 |
parents | 93397c4633f6 |
children | 835ccc2a5ef1 |
comparison
equal
deleted
inserted
replaced
37545:93397c4633f6 | 37546:3a2367e6c6f2 |
---|---|
491 | 491 |
492 # TODO require to be part of a batched primitive, use futures. | 492 # TODO require to be part of a batched primitive, use futures. |
493 def _call(self, name, **args): | 493 def _call(self, name, **args): |
494 """Call a wire protocol command with arguments.""" | 494 """Call a wire protocol command with arguments.""" |
495 | 495 |
496 # Having this early has a side-effect of importing wireprotov2server, | |
497 # which has the side-effect of ensuring commands are registered. | |
498 | |
499 # TODO modify user-agent to reflect v2. | |
500 headers = { | |
501 r'Accept': wireprotov2server.FRAMINGTYPE, | |
502 r'Content-Type': wireprotov2server.FRAMINGTYPE, | |
503 } | |
504 | |
496 # TODO permissions should come from capabilities results. | 505 # TODO permissions should come from capabilities results. |
497 permission = wireproto.commandsv2[name].permission | 506 permission = wireproto.commandsv2[name].permission |
498 if permission not in ('push', 'pull'): | 507 if permission not in ('push', 'pull'): |
499 raise error.ProgrammingError('unknown permission type: %s' % | 508 raise error.ProgrammingError('unknown permission type: %s' % |
500 permission) | 509 permission) |
504 'pull': 'ro', | 513 'pull': 'ro', |
505 }[permission] | 514 }[permission] |
506 | 515 |
507 url = '%s/api/%s/%s/%s' % (self.url, wireprotov2server.HTTPV2, | 516 url = '%s/api/%s/%s/%s' % (self.url, wireprotov2server.HTTPV2, |
508 permission, name) | 517 permission, name) |
509 | |
510 # TODO modify user-agent to reflect v2. | |
511 headers = { | |
512 r'Accept': wireprotov2server.FRAMINGTYPE, | |
513 r'Content-Type': wireprotov2server.FRAMINGTYPE, | |
514 } | |
515 | 518 |
516 # TODO this should be part of a generic peer for the frame-based | 519 # TODO this should be part of a generic peer for the frame-based |
517 # protocol. | 520 # protocol. |
518 reactor = wireprotoframing.clientreactor(hasmultiplesend=False, | 521 reactor = wireprotoframing.clientreactor(hasmultiplesend=False, |
519 buffersends=True) | 522 buffersends=True) |