diff 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
line wrap: on
line diff
--- a/mercurial/httppeer.py	Mon Apr 09 19:35:04 2018 -0700
+++ b/mercurial/httppeer.py	Mon Apr 09 19:35:39 2018 -0700
@@ -493,6 +493,15 @@
     def _call(self, name, **args):
         """Call a wire protocol command with arguments."""
 
+        # Having this early has a side-effect of importing wireprotov2server,
+        # which has the side-effect of ensuring commands are registered.
+
+        # TODO modify user-agent to reflect v2.
+        headers = {
+            r'Accept': wireprotov2server.FRAMINGTYPE,
+            r'Content-Type': wireprotov2server.FRAMINGTYPE,
+        }
+
         # TODO permissions should come from capabilities results.
         permission = wireproto.commandsv2[name].permission
         if permission not in ('push', 'pull'):
@@ -507,12 +516,6 @@
         url = '%s/api/%s/%s/%s' % (self.url, wireprotov2server.HTTPV2,
                                    permission, name)
 
-        # TODO modify user-agent to reflect v2.
-        headers = {
-            r'Accept': wireprotov2server.FRAMINGTYPE,
-            r'Content-Type': wireprotov2server.FRAMINGTYPE,
-        }
-
         # TODO this should be part of a generic peer for the frame-based
         # protocol.
         reactor = wireprotoframing.clientreactor(hasmultiplesend=False,