1 $ . $TESTDIR/wireprotohelpers.sh |
1 $ . $TESTDIR/wireprotohelpers.sh |
2 |
2 |
3 $ hg init server |
3 $ hg init server |
|
4 $ hg -R server serve -p $HGPORT -d --pid-file hg.pid -E error.log |
|
5 $ cat hg.pid > $DAEMON_PIDS |
|
6 |
|
7 A normal capabilities request is serviced for version 1 |
|
8 |
|
9 $ sendhttpraw << EOF |
|
10 > httprequest GET ?cmd=capabilities |
|
11 > user-agent: test |
|
12 > EOF |
|
13 using raw connection to peer |
|
14 s> GET /?cmd=capabilities HTTP/1.1\r\n |
|
15 s> Accept-Encoding: identity\r\n |
|
16 s> user-agent: test\r\n |
|
17 s> host: $LOCALIP:$HGPORT\r\n (glob) |
|
18 s> \r\n |
|
19 s> makefile('rb', None) |
|
20 s> HTTP/1.1 200 Script output follows\r\n |
|
21 s> Server: testing stub value\r\n |
|
22 s> Date: $HTTP_DATE$\r\n |
|
23 s> Content-Type: application/mercurial-0.1\r\n |
|
24 s> Content-Length: 458\r\n |
|
25 s> \r\n |
|
26 s> batch branchmap $USUAL_BUNDLE2_CAPS_SERVER$ changegroupsubset compression=$BUNDLE2_COMPRESSIONS$ getbundle httpheader=1024 httpmediatype=0.1rx,0.1tx,0.2tx known lookup pushkey streamreqs=generaldelta,revlogv1 unbundle=HG10GZ,HG10BZ,HG10UN unbundlehash |
|
27 |
|
28 A proper request without the API server enabled returns the legacy response |
|
29 |
|
30 $ sendhttpraw << EOF |
|
31 > httprequest GET ?cmd=capabilities |
|
32 > user-agent: test |
|
33 > x-hgupgrade-1: foo |
|
34 > x-hgproto-1: cbor |
|
35 > EOF |
|
36 using raw connection to peer |
|
37 s> GET /?cmd=capabilities HTTP/1.1\r\n |
|
38 s> Accept-Encoding: identity\r\n |
|
39 s> user-agent: test\r\n |
|
40 s> x-hgproto-1: cbor\r\n |
|
41 s> x-hgupgrade-1: foo\r\n |
|
42 s> host: $LOCALIP:$HGPORT\r\n (glob) |
|
43 s> \r\n |
|
44 s> makefile('rb', None) |
|
45 s> HTTP/1.1 200 Script output follows\r\n |
|
46 s> Server: testing stub value\r\n |
|
47 s> Date: $HTTP_DATE$\r\n |
|
48 s> Content-Type: application/mercurial-0.1\r\n |
|
49 s> Content-Length: 458\r\n |
|
50 s> \r\n |
|
51 s> batch branchmap $USUAL_BUNDLE2_CAPS_SERVER$ changegroupsubset compression=$BUNDLE2_COMPRESSIONS$ getbundle httpheader=1024 httpmediatype=0.1rx,0.1tx,0.2tx known lookup pushkey streamreqs=generaldelta,revlogv1 unbundle=HG10GZ,HG10BZ,HG10UN unbundlehash |
|
52 |
|
53 Restart with just API server enabled. This enables serving the new format. |
|
54 |
|
55 $ killdaemons.py |
|
56 $ cat error.log |
|
57 |
|
58 $ cat >> server/.hg/hgrc << EOF |
|
59 > [experimental] |
|
60 > web.apiserver = true |
|
61 > EOF |
|
62 |
|
63 $ hg -R server serve -p $HGPORT -d --pid-file hg.pid -E error.log |
|
64 $ cat hg.pid > $DAEMON_PIDS |
|
65 |
|
66 X-HgUpgrade-<N> without CBOR advertisement uses legacy response |
|
67 |
|
68 $ sendhttpraw << EOF |
|
69 > httprequest GET ?cmd=capabilities |
|
70 > user-agent: test |
|
71 > x-hgupgrade-1: foo bar |
|
72 > EOF |
|
73 using raw connection to peer |
|
74 s> GET /?cmd=capabilities HTTP/1.1\r\n |
|
75 s> Accept-Encoding: identity\r\n |
|
76 s> user-agent: test\r\n |
|
77 s> x-hgupgrade-1: foo bar\r\n |
|
78 s> host: $LOCALIP:$HGPORT\r\n (glob) |
|
79 s> \r\n |
|
80 s> makefile('rb', None) |
|
81 s> HTTP/1.1 200 Script output follows\r\n |
|
82 s> Server: testing stub value\r\n |
|
83 s> Date: $HTTP_DATE$\r\n |
|
84 s> Content-Type: application/mercurial-0.1\r\n |
|
85 s> Content-Length: 458\r\n |
|
86 s> \r\n |
|
87 s> batch branchmap $USUAL_BUNDLE2_CAPS_SERVER$ changegroupsubset compression=$BUNDLE2_COMPRESSIONS$ getbundle httpheader=1024 httpmediatype=0.1rx,0.1tx,0.2tx known lookup pushkey streamreqs=generaldelta,revlogv1 unbundle=HG10GZ,HG10BZ,HG10UN unbundlehash |
|
88 |
|
89 X-HgUpgrade-<N> without known serialization in X-HgProto-<N> uses legacy response |
|
90 |
|
91 $ sendhttpraw << EOF |
|
92 > httprequest GET ?cmd=capabilities |
|
93 > user-agent: test |
|
94 > x-hgupgrade-1: foo bar |
|
95 > x-hgproto-1: some value |
|
96 > EOF |
|
97 using raw connection to peer |
|
98 s> GET /?cmd=capabilities HTTP/1.1\r\n |
|
99 s> Accept-Encoding: identity\r\n |
|
100 s> user-agent: test\r\n |
|
101 s> x-hgproto-1: some value\r\n |
|
102 s> x-hgupgrade-1: foo bar\r\n |
|
103 s> host: $LOCALIP:$HGPORT\r\n (glob) |
|
104 s> \r\n |
|
105 s> makefile('rb', None) |
|
106 s> HTTP/1.1 200 Script output follows\r\n |
|
107 s> Server: testing stub value\r\n |
|
108 s> Date: $HTTP_DATE$\r\n |
|
109 s> Content-Type: application/mercurial-0.1\r\n |
|
110 s> Content-Length: 458\r\n |
|
111 s> \r\n |
|
112 s> batch branchmap $USUAL_BUNDLE2_CAPS_SERVER$ changegroupsubset compression=$BUNDLE2_COMPRESSIONS$ getbundle httpheader=1024 httpmediatype=0.1rx,0.1tx,0.2tx known lookup pushkey streamreqs=generaldelta,revlogv1 unbundle=HG10GZ,HG10BZ,HG10UN unbundlehash |
|
113 |
|
114 X-HgUpgrade-<N> + X-HgProto-<N> headers trigger new response format |
|
115 |
|
116 $ sendhttpraw << EOF |
|
117 > httprequest GET ?cmd=capabilities |
|
118 > user-agent: test |
|
119 > x-hgupgrade-1: foo bar |
|
120 > x-hgproto-1: cbor |
|
121 > EOF |
|
122 using raw connection to peer |
|
123 s> GET /?cmd=capabilities HTTP/1.1\r\n |
|
124 s> Accept-Encoding: identity\r\n |
|
125 s> user-agent: test\r\n |
|
126 s> x-hgproto-1: cbor\r\n |
|
127 s> x-hgupgrade-1: foo bar\r\n |
|
128 s> host: $LOCALIP:$HGPORT\r\n (glob) |
|
129 s> \r\n |
|
130 s> makefile('rb', None) |
|
131 s> HTTP/1.1 200 OK\r\n |
|
132 s> Server: testing stub value\r\n |
|
133 s> Date: $HTTP_DATE$\r\n |
|
134 s> Content-Type: application/mercurial-cbor\r\n |
|
135 s> Content-Length: 496\r\n |
|
136 s> \r\n |
|
137 s> \xa3Dapis\xa0GapibaseDapi/Nv1capabilitiesY\x01\xcabatch branchmap $USUAL_BUNDLE2_CAPS_SERVER$ changegroupsubset compression=$BUNDLE2_COMPRESSIONS$ getbundle httpheader=1024 httpmediatype=0.1rx,0.1tx,0.2tx known lookup pushkey streamreqs=generaldelta,revlogv1 unbundle=HG10GZ,HG10BZ,HG10UN unbundlehash |
|
138 cbor> {b'apibase': b'api/', b'apis': {}, b'v1capabilities': b'batch branchmap $USUAL_BUNDLE2_CAPS_SERVER$ changegroupsubset compression=$BUNDLE2_COMPRESSIONS$ getbundle httpheader=1024 httpmediatype=0.1rx,0.1tx,0.2tx known lookup pushkey streamreqs=generaldelta,revlogv1 unbundle=HG10GZ,HG10BZ,HG10UN unbundlehash'} |
|
139 |
|
140 Restart server to enable HTTPv2 |
|
141 |
|
142 $ killdaemons.py |
4 $ enablehttpv2 server |
143 $ enablehttpv2 server |
5 $ hg -R server serve -p $HGPORT -d --pid-file hg.pid -E error.log |
144 $ hg -R server serve -p $HGPORT -d --pid-file hg.pid -E error.log |
6 $ cat hg.pid > $DAEMON_PIDS |
145 |
7 |
146 Only requested API services are returned |
8 capabilities request returns an array of capability strings |
147 |
|
148 $ sendhttpraw << EOF |
|
149 > httprequest GET ?cmd=capabilities |
|
150 > user-agent: test |
|
151 > x-hgupgrade-1: foo bar |
|
152 > x-hgproto-1: cbor |
|
153 > EOF |
|
154 using raw connection to peer |
|
155 s> GET /?cmd=capabilities HTTP/1.1\r\n |
|
156 s> Accept-Encoding: identity\r\n |
|
157 s> user-agent: test\r\n |
|
158 s> x-hgproto-1: cbor\r\n |
|
159 s> x-hgupgrade-1: foo bar\r\n |
|
160 s> host: $LOCALIP:$HGPORT\r\n (glob) |
|
161 s> \r\n |
|
162 s> makefile('rb', None) |
|
163 s> HTTP/1.1 200 OK\r\n |
|
164 s> Server: testing stub value\r\n |
|
165 s> Date: $HTTP_DATE$\r\n |
|
166 s> Content-Type: application/mercurial-cbor\r\n |
|
167 s> Content-Length: 496\r\n |
|
168 s> \r\n |
|
169 s> \xa3Dapis\xa0GapibaseDapi/Nv1capabilitiesY\x01\xcabatch branchmap $USUAL_BUNDLE2_CAPS_SERVER$ changegroupsubset compression=$BUNDLE2_COMPRESSIONS$ getbundle httpheader=1024 httpmediatype=0.1rx,0.1tx,0.2tx known lookup pushkey streamreqs=generaldelta,revlogv1 unbundle=HG10GZ,HG10BZ,HG10UN unbundlehash |
|
170 cbor> {b'apibase': b'api/', b'apis': {}, b'v1capabilities': b'batch branchmap $USUAL_BUNDLE2_CAPS_SERVER$ changegroupsubset compression=$BUNDLE2_COMPRESSIONS$ getbundle httpheader=1024 httpmediatype=0.1rx,0.1tx,0.2tx known lookup pushkey streamreqs=generaldelta,revlogv1 unbundle=HG10GZ,HG10BZ,HG10UN unbundlehash'} |
|
171 |
|
172 Request for HTTPv2 service returns information about it |
|
173 |
|
174 $ sendhttpraw << EOF |
|
175 > httprequest GET ?cmd=capabilities |
|
176 > user-agent: test |
|
177 > x-hgupgrade-1: exp-http-v2-0001 foo bar |
|
178 > x-hgproto-1: cbor |
|
179 > EOF |
|
180 using raw connection to peer |
|
181 s> GET /?cmd=capabilities HTTP/1.1\r\n |
|
182 s> Accept-Encoding: identity\r\n |
|
183 s> user-agent: test\r\n |
|
184 s> x-hgproto-1: cbor\r\n |
|
185 s> x-hgupgrade-1: exp-http-v2-0001 foo bar\r\n |
|
186 s> host: $LOCALIP:$HGPORT\r\n (glob) |
|
187 s> \r\n |
|
188 s> makefile('rb', None) |
|
189 s> HTTP/1.1 200 OK\r\n |
|
190 s> Server: testing stub value\r\n |
|
191 s> Date: $HTTP_DATE$\r\n |
|
192 s> Content-Type: application/mercurial-cbor\r\n |
|
193 s> Content-Length: 879\r\n |
|
194 s> \r\n |
|
195 s> \xa3Dapis\xa1Pexp-http-v2-0001\xa2Hcommands\xa7Eheads\xa2Dargs\xa1Jpubliconly\xf4Kpermissions\x81DpullEknown\xa2Dargs\xa1Enodes\x81HdeadbeefKpermissions\x81DpullFlookup\xa2Dargs\xa1CkeyCfooKpermissions\x81DpullGpushkey\xa2Dargs\xa4CkeyCkeyCnewCnewColdColdInamespaceBnsKpermissions\x81DpushHlistkeys\xa2Dargs\xa1InamespaceBnsKpermissions\x81DpullIbranchmap\xa2Dargs\xa0Kpermissions\x81DpullLcapabilities\xa2Dargs\xa0Kpermissions\x81DpullKcompression\x82\xa1DnameDzstd\xa1DnameDzlibGapibaseDapi/Nv1capabilitiesY\x01\xcabatch branchmap $USUAL_BUNDLE2_CAPS_SERVER$ changegroupsubset compression=$BUNDLE2_COMPRESSIONS$ getbundle httpheader=1024 httpmediatype=0.1rx,0.1tx,0.2tx known lookup pushkey streamreqs=generaldelta,revlogv1 unbundle=HG10GZ,HG10BZ,HG10UN unbundlehash |
|
196 cbor> {b'apibase': b'api/', b'apis': {b'exp-http-v2-0001': {b'commands': {b'branchmap': {b'args': {}, b'permissions': [b'pull']}, b'capabilities': {b'args': {}, b'permissions': [b'pull']}, b'heads': {b'args': {b'publiconly': False}, b'permissions': [b'pull']}, b'known': {b'args': {b'nodes': [b'deadbeef']}, b'permissions': [b'pull']}, b'listkeys': {b'args': {b'namespace': b'ns'}, b'permissions': [b'pull']}, b'lookup': {b'args': {b'key': b'foo'}, b'permissions': [b'pull']}, b'pushkey': {b'args': {b'key': b'key', b'namespace': b'ns', b'new': b'new', b'old': b'old'}, b'permissions': [b'push']}}, b'compression': [{b'name': b'zstd'}, {b'name': b'zlib'}]}}, b'v1capabilities': b'batch branchmap $USUAL_BUNDLE2_CAPS_SERVER$ changegroupsubset compression=$BUNDLE2_COMPRESSIONS$ getbundle httpheader=1024 httpmediatype=0.1rx,0.1tx,0.2tx known lookup pushkey streamreqs=generaldelta,revlogv1 unbundle=HG10GZ,HG10BZ,HG10UN unbundlehash'} |
|
197 |
|
198 capabilities command returns expected info |
9 |
199 |
10 $ sendhttpv2peer << EOF |
200 $ sendhttpv2peer << EOF |
11 > command capabilities |
201 > command capabilities |
12 > EOF |
202 > EOF |
13 creating http peer for wire protocol version 2 |
203 creating http peer for wire protocol version 2 |