Show More
@@ -9,3 +9,147 b' return multiple response types.' | |||||
9 |
|
9 | |||
10 | The protocol is synchronous and does not support multiplexing (concurrent |
|
10 | The protocol is synchronous and does not support multiplexing (concurrent | |
11 | commands). |
|
11 | commands). | |
|
12 | ||||
|
13 | Transport Protocols | |||
|
14 | =================== | |||
|
15 | ||||
|
16 | HTTP Transport | |||
|
17 | -------------- | |||
|
18 | ||||
|
19 | Commands are issued as HTTP/1.0 or HTTP/1.1 requests. Commands are | |||
|
20 | sent to the base URL of the repository with the command name sent in | |||
|
21 | the ``cmd`` query string parameter. e.g. | |||
|
22 | ``https://example.com/repo?cmd=capabilities``. The HTTP method is ``GET`` | |||
|
23 | or ``POST`` depending on the command and whether there is a request | |||
|
24 | body. | |||
|
25 | ||||
|
26 | Command arguments can be sent multiple ways. | |||
|
27 | ||||
|
28 | The simplest is part of the URL query string using ``x-www-form-urlencoded`` | |||
|
29 | encoding (see Python's ``urllib.urlencode()``. However, many servers impose | |||
|
30 | length limitations on the URL. So this mechanism is typically only used if | |||
|
31 | the server doesn't support other mechanisms. | |||
|
32 | ||||
|
33 | If the server supports the ``httpheader`` capability, command arguments can | |||
|
34 | be sent in HTTP request headers named ``X-HgArg-<N>`` where ``<N>`` is an | |||
|
35 | integer starting at 1. A ``x-www-form-urlencoded`` representation of the | |||
|
36 | arguments is obtained. This full string is then split into chunks and sent | |||
|
37 | in numbered ``X-HgArg-<N>`` headers. The maximum length of each HTTP header | |||
|
38 | is defined by the server in the ``httpheader`` capability value, which defaults | |||
|
39 | to ``1024``. The server reassembles the encoded arguments string by | |||
|
40 | concatenating the ``X-HgArg-<N>`` headers then URL decodes them into a | |||
|
41 | dictionary. | |||
|
42 | ||||
|
43 | The list of ``X-HgArg-<N>`` headers should be added to the ``Vary`` request | |||
|
44 | header to instruct caches to take these headers into consideration when caching | |||
|
45 | requests. | |||
|
46 | ||||
|
47 | If the server supports the ``httppostargs`` capability, the client | |||
|
48 | may send command arguments in the HTTP request body as part of an | |||
|
49 | HTTP POST request. The command arguments will be URL encoded just like | |||
|
50 | they would for sending them via HTTP headers. However, no splitting is | |||
|
51 | performed: the raw arguments are included in the HTTP request body. | |||
|
52 | ||||
|
53 | The client sends a ``X-HgArgs-Post`` header with the string length of the | |||
|
54 | encoded arguments data. Additional data may be included in the HTTP | |||
|
55 | request body immediately following the argument data. The offset of the | |||
|
56 | non-argument data is defined by the ``X-HgArgs-Post`` header. The | |||
|
57 | ``X-HgArgs-Post`` header is not required if there is no argument data. | |||
|
58 | ||||
|
59 | Additional command data can be sent as part of the HTTP request body. The | |||
|
60 | default ``Content-Type`` when sending data is ``application/mercurial-0.1``. | |||
|
61 | A ``Content-Length`` header is currently always sent. | |||
|
62 | ||||
|
63 | Example HTTP requests:: | |||
|
64 | ||||
|
65 | GET /repo?cmd=capabilities | |||
|
66 | X-HgArg-1: foo=bar&baz=hello%20world | |||
|
67 | ||||
|
68 | The ``Content-Type`` HTTP response header identifies the response as coming | |||
|
69 | from Mercurial and can also be used to signal an error has occurred. | |||
|
70 | ||||
|
71 | The ``application/mercurial-0.1`` media type indicates a generic Mercurial | |||
|
72 | response. It matches the media type sent by the client. | |||
|
73 | ||||
|
74 | The ``application/hg-error`` media type indicates a generic error occurred. | |||
|
75 | The content of the HTTP response body typically holds text describing the | |||
|
76 | error. | |||
|
77 | ||||
|
78 | The ``application/hg-changegroup`` media type indicates a changegroup response | |||
|
79 | type. | |||
|
80 | ||||
|
81 | Clients also accept the ``text/plain`` media type. All other media | |||
|
82 | types should cause the client to error. | |||
|
83 | ||||
|
84 | Clients should issue a ``User-Agent`` request header that identifies the client. | |||
|
85 | The server should not use the ``User-Agent`` for feature detection. | |||
|
86 | ||||
|
87 | A command returning a ``string`` response issues the | |||
|
88 | ``application/mercurial-0.1`` media type and the HTTP response body contains | |||
|
89 | the raw string value. A ``Content-Length`` header is typically issued. | |||
|
90 | ||||
|
91 | A command returning a ``stream`` response issues the | |||
|
92 | ``application/mercurial-0.1`` media type and the HTTP response is typically | |||
|
93 | using *chunked transfer* (``Transfer-Encoding: chunked``). | |||
|
94 | ||||
|
95 | SSH Transport | |||
|
96 | ============= | |||
|
97 | ||||
|
98 | The SSH transport is a custom text-based protocol suitable for use over any | |||
|
99 | bi-directional stream transport. It is most commonly used with SSH. | |||
|
100 | ||||
|
101 | A SSH transport server can be started with ``hg serve --stdio``. The stdin, | |||
|
102 | stderr, and stdout file descriptors of the started process are used to exchange | |||
|
103 | data. When Mercurial connects to a remote server over SSH, it actually starts | |||
|
104 | a ``hg serve --stdio`` process on the remote server. | |||
|
105 | ||||
|
106 | Commands are issued by sending the command name followed by a trailing newline | |||
|
107 | ``\n`` to the server. e.g. ``capabilities\n``. | |||
|
108 | ||||
|
109 | Command arguments are sent in the following format:: | |||
|
110 | ||||
|
111 | <argument> <length>\n<value> | |||
|
112 | ||||
|
113 | That is, the argument string name followed by a space followed by the | |||
|
114 | integer length of the value (expressed as a string) followed by a newline | |||
|
115 | (``\n``) followed by the raw argument value. | |||
|
116 | ||||
|
117 | Dictionary arguments are encoded differently:: | |||
|
118 | ||||
|
119 | <argument> <# elements>\n | |||
|
120 | <key1> <length1>\n<value1> | |||
|
121 | <key2> <length2>\n<value2> | |||
|
122 | ... | |||
|
123 | ||||
|
124 | Non-argument data is sent immediately after the final argument value. It is | |||
|
125 | encoded in chunks:: | |||
|
126 | ||||
|
127 | <length>\n<data> | |||
|
128 | ||||
|
129 | Each command declares a list of supported arguments and their types. If a | |||
|
130 | client sends an unknown argument to the server, the server should abort | |||
|
131 | immediately. The special argument ``*`` in a command's definition indicates | |||
|
132 | that all argument names are allowed. | |||
|
133 | ||||
|
134 | The definition of supported arguments and types is initially made when a | |||
|
135 | new command is implemented. The client and server must initially independently | |||
|
136 | agree on the arguments and their types. This initial set of arguments can be | |||
|
137 | supplemented through the presence of *capabilities* advertised by the server. | |||
|
138 | ||||
|
139 | Each command has a defined expected response type. | |||
|
140 | ||||
|
141 | A ``string`` response type is a length framed value. The response consists of | |||
|
142 | the string encoded integer length of a value followed by a newline (``\n``) | |||
|
143 | followed by the value. Empty values are allowed (and are represented as | |||
|
144 | ``0\n``). | |||
|
145 | ||||
|
146 | A ``stream`` response type consists of raw bytes of data. There is no framing. | |||
|
147 | ||||
|
148 | A generic error response type is also supported. It consists of a an error | |||
|
149 | message written to ``stderr`` followed by ``\n-\n``. In addition, ``\n`` is | |||
|
150 | written to ``stdout``. | |||
|
151 | ||||
|
152 | If the server receives an unknown command, it will send an empty ``string`` | |||
|
153 | response. | |||
|
154 | ||||
|
155 | The server terminates if it receives an empty command (a ``\n`` character). |
General Comments 0
You need to be logged in to leave comments.
Login now