Mercurial > public > mercurial-scm > hg
diff mercurial/help/internals/wireprotocol.txt @ 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 | 301a1d2e8016 |
children | b2fa1591fb44 |
line wrap: on
line diff
--- a/mercurial/help/internals/wireprotocol.txt Tue Apr 10 18:13:28 2018 -0700 +++ b/mercurial/help/internals/wireprotocol.txt Tue Apr 10 14:29:15 2018 -0700 @@ -42,8 +42,44 @@ The client sends a ``capabilities`` command request (``?cmd=capabilities``) as soon as HTTP requests may be issued. -The server responds with a capabilities string, which the client parses to -learn about the server's abilities. +By default, the server responds with a version 1 capabilities string, which +the client parses to learn about the server's abilities. The ``Content-Type`` +for this response is ``application/mercurial-0.1`` or +``application/mercurial-0.2`` depending on whether the client advertised +support for version ``0.2`` in its request. (Clients aren't supposed to +advertise support for ``0.2`` until the capabilities response indicates +the server's support for that media type. However, a client could +conceivably cache this metadata and issue the capabilities request in such +a way to elicit an ``application/mercurial-0.2`` response.) + +Clients wishing to switch to a newer API service may send an +``X-HgUpgrade-<X>`` header containing a space-delimited list of API service +names the client is capable of speaking. The request MUST also include an +``X-HgProto-<X>`` header advertising a known serialization format for the +response. ``cbor`` is currently the only defined serialization format. + +If the request contains these headers, the response ``Content-Type`` MAY +be for a different media type. e.g. ``application/mercurial-cbor`` if the +client advertises support for CBOR. + +The response MUST be deserializable to a map with the following keys: + +apibase + URL path to API services, relative to the repository root. e.g. ``api/``. + +apis + A map of API service names to API descriptors. An API descriptor contains + more details about that API. In the case of the HTTP Version 2 Transport, + it will be the normal response to a ``capabilities`` command. + + Only the services advertised by the client that are also available on + the server are advertised. + +v1capabilities + The capabilities string that would be returned by a version 1 response. + +The client can then inspect the server-advertised APIs and decide which +API to use, including continuing to use the HTTP Version 1 Transport. HTTP Version 1 Transport ------------------------ @@ -123,6 +159,9 @@ The content of the HTTP response body typically holds text describing the error. +The ``application/mercurial-cbor`` media type indicates a CBOR payload +and should be interpreted as identical to ``application/cbor``. + Behavior of media types is further described in the ``Content Negotiation`` section below. @@ -1252,6 +1291,12 @@ Indicates the client supports receiving ``application/mercurial-0.2`` responses. +cbor + Indicates the client supports receiving ``application/mercurial-cbor`` + responses. + + (Only intended to be used with version 2 transports.) + comp Indicates compression formats the client can decode. Value is a list of comma delimited strings identifying compression formats ordered from