##// END OF EJS Templates
wireproto: function for testing if wire protocol command is available...
Gregory Szorc -
r36000:5a56bf41 default
parent child Browse files
Show More
@@ -357,6 +357,14 b' class hgweb(object):'
357 query = req.env[r'QUERY_STRING'].partition(r'&')[0]
357 query = req.env[r'QUERY_STRING'].partition(r'&')[0]
358 query = query.partition(r';')[0]
358 query = query.partition(r';')[0]
359
359
360 # The ``cmd`` request parameter is used by both the wire protocol
361 # and hgweb. We route all known wire protocol commands to the
362 # wire protocol handler, even if the command isn't available for
363 # this transport. That's better for machine clients in the case
364 # of an errant request to an unavailable protocol command. And it
365 # prevents hgweb from accidentally using ``cmd`` values used by
366 # the wire protocol.
367
360 # process this if it's a protocol request
368 # process this if it's a protocol request
361 # protocol bits don't need to create any URLs
369 # protocol bits don't need to create any URLs
362 # and the clients always use the old URL structure
370 # and the clients always use the old URL structure
@@ -691,6 +691,12 b' class commanddict(dict):'
691
691
692 return super(commanddict, self).__setitem__(k, v)
692 return super(commanddict, self).__setitem__(k, v)
693
693
694 def commandavailable(self, command, proto):
695 """Determine if a command is available for the requested protocol."""
696 # For now, commands are available for all protocols. So do a simple
697 # membership test.
698 return command in self
699
694 commands = commanddict()
700 commands = commanddict()
695
701
696 def wireprotocommand(name, args=''):
702 def wireprotocommand(name, args=''):
@@ -223,6 +223,13 b' def callhttp(repo, req, cmd):'
223 yield chunk
223 yield chunk
224
224
225 rsp = wireproto.dispatch(repo, proto, cmd)
225 rsp = wireproto.dispatch(repo, proto, cmd)
226
227 if not wireproto.commands.commandavailable(cmd, proto):
228 req.respond(HTTP_OK, HGERRTYPE,
229 body=_('requested wire protocol command is not available '
230 'over HTTP'))
231 return []
232
226 if isinstance(rsp, bytes):
233 if isinstance(rsp, bytes):
227 req.respond(HTTP_OK, HGTYPE, body=rsp)
234 req.respond(HTTP_OK, HGTYPE, body=rsp)
228 return []
235 return []
@@ -351,7 +358,7 b' class sshserver(abstractserverproto):'
351
358
352 def serve_one(self):
359 def serve_one(self):
353 cmd = self._fin.readline()[:-1]
360 cmd = self._fin.readline()[:-1]
354 if cmd and cmd in wireproto.commands:
361 if cmd and wireproto.commands.commandavailable(cmd, self):
355 rsp = wireproto.dispatch(self._repo, self, cmd)
362 rsp = wireproto.dispatch(self._repo, self, cmd)
356 self._handlers[rsp.__class__](self, rsp)
363 self._handlers[rsp.__class__](self, rsp)
357 elif cmd:
364 elif cmd:
General Comments 0
You need to be logged in to leave comments. Login now