comparison mercurial/debugcommands.py @ 37557:734515aca84d

wireproto: define and implement HTTP handshake to upgrade protocol When clients connect to repositories over HTTP, they issue a request to the well-known URL "?cmd=capabilities" to fetch the repository capabilities. This is the handshake portion of the HTTP protocol. This commit defines a mechanism to use that HTTP request to return information about modern server features. If a client sends an X-HgUpgrade-* header containing a list of client-supported API names, the server responds with a response containing information about available services. This includes the normal capabilities string. So if the server doesn't support any newer services, the client can easily fall back. By advertising supported services from clients, server operators can see and log what client support exists in the wild. This will also help with debugging. The response contains the base path to API services. We know there are potential issues with the <repo>/api/ URL space conflicting with hgwebdir and subrepos. By making the API URL dynamic from the perspective of the client, the URL for APIs is not subject to backwards compatibility concerns - at least as long as a ?cmd=capabilities request is made. We've also defined the ``cbor`` client capability for the X-HgProto-* header. This MUST be sent in order to get the modern response from "?cmd=capabilities". During implementation, I initially always sent an application/mercurial-cbor response. However, the handshake mechanism will be more future compatible if the client is in charge of which formats to request. We already perform content negotiation from X-HgProto-*, so keying off this for the capabilities response feels appropriate. In addition, I initially used application/cbor. However, it is conceivable that a non-Mercurial server could serve application/cbor. To rule out this possibility, I've invented a new media type that is Mercurial specific and can't be confused for generic CBOR. Differential Revision: https://phab.mercurial-scm.org/D3242
author Gregory Szorc <gregory.szorc@gmail.com>
date Tue, 10 Apr 2018 14:29:15 -0700
parents 6b08cf6b900f
children 8a73132214a3
comparison
equal deleted inserted replaced
37556:b77aa48ba690 37557:734515aca84d
30 hex, 30 hex,
31 nullhex, 31 nullhex,
32 nullid, 32 nullid,
33 nullrev, 33 nullrev,
34 short, 34 short,
35 )
36 from .thirdparty import (
37 cbor,
35 ) 38 )
36 from . import ( 39 from . import (
37 bundle2, 40 bundle2,
38 changegroup, 41 changegroup,
39 cmdutil, 42 cmdutil,
3043 # determining the request method. Override that to use our 3046 # determining the request method. Override that to use our
3044 # explicitly requested method. 3047 # explicitly requested method.
3045 req.get_method = lambda: method 3048 req.get_method = lambda: method
3046 3049
3047 try: 3050 try:
3048 opener.open(req).read() 3051 res = opener.open(req)
3052 body = res.read()
3049 except util.urlerr.urlerror as e: 3053 except util.urlerr.urlerror as e:
3050 e.read() 3054 e.read()
3055 continue
3056
3057 if res.headers.get('Content-Type') == 'application/mercurial-cbor':
3058 ui.write(_('cbor> %s\n') % stringutil.pprint(cbor.loads(body)))
3051 3059
3052 elif action == 'close': 3060 elif action == 'close':
3053 peer.close() 3061 peer.close()
3054 elif action == 'readavailable': 3062 elif action == 'readavailable':
3055 if not stdout or not stderr: 3063 if not stdout or not stderr: