##// END OF EJS Templates
wireproto: define content negotiation for HTTPv2...
Gregory Szorc -
r37068:37d7a1d1 default
parent child Browse files
Show More
@@ -187,6 +187,19 b' exchange takes place. This provides a be'
187 Requests to unknown commands or URLS result in an HTTP 404.
187 Requests to unknown commands or URLS result in an HTTP 404.
188 TODO formally define response type, how error is communicated, etc.
188 TODO formally define response type, how error is communicated, etc.
189
189
190 HTTP request and response bodies use the *TBD Protocol* for media exchange.
191
192 Clients and servers MUST advertise the ``TBD`` media type via the
193 ``Content-Type`` request and response headers. In addition, clients MUST
194 advertise this media type value in their ``Accept`` request header in all
195 requests.
196
197 Servers receiving requests without an ``Accept`` header SHOULD respond with
198 an HTTP 406.
199
200 Servers receiving requests with an invalid ``Content-Type`` header SHOULD
201 respond with an HTTP 415.
202
190 SSH Protocol
203 SSH Protocol
191 ============
204 ============
192
205
@@ -32,6 +32,7 b' HTTP_OK = 200'
32 HGTYPE = 'application/mercurial-0.1'
32 HGTYPE = 'application/mercurial-0.1'
33 HGTYPE2 = 'application/mercurial-0.2'
33 HGTYPE2 = 'application/mercurial-0.2'
34 HGERRTYPE = 'application/hg-error'
34 HGERRTYPE = 'application/hg-error'
35 HTTPV2TYPE = 'application/mercurial-tbd'
35
36
36 HTTPV2 = wireprototypes.HTTPV2
37 HTTPV2 = wireprototypes.HTTPV2
37 SSHV1 = wireprototypes.SSHV1
38 SSHV1 = wireprototypes.SSHV1
@@ -335,6 +336,23 b' def _handlehttpv2request(rctx, req, res,'
335 res.setbodybytes(_('invalid wire protocol command: %s') % command)
336 res.setbodybytes(_('invalid wire protocol command: %s') % command)
336 return
337 return
337
338
339 if req.headers.get(b'Accept') != HTTPV2TYPE:
340 res.status = b'406 Not Acceptable'
341 res.headers[b'Content-Type'] = b'text/plain'
342 res.setbodybytes(_('client MUST specify Accept header with value: %s\n')
343 % HTTPV2TYPE)
344 return
345
346 if (b'Content-Type' in req.headers
347 and req.headers[b'Content-Type'] != HTTPV2TYPE):
348 res.status = b'415 Unsupported Media Type'
349 # TODO we should send a response with appropriate media type,
350 # since client does Accept it.
351 res.headers[b'Content-Type'] = b'text/plain'
352 res.setbodybytes(_('client MUST send Content-Type header with '
353 'value: %s\n') % HTTPV2TYPE)
354 return
355
338 # We don't do anything meaningful yet.
356 # We don't do anything meaningful yet.
339 res.status = b'200 OK'
357 res.status = b'200 OK'
340 res.headers[b'Content-Type'] = b'text/plain'
358 res.headers[b'Content-Type'] = b'text/plain'
@@ -1,4 +1,5 b''
1 $ HTTPV2=exp-http-v2-0001
1 $ HTTPV2=exp-http-v2-0001
2 $ MEDIATYPE=application/mercurial-tbd
2
3
3 $ send() {
4 $ send() {
4 > hg --verbose debugwireproto --peer raw http://$LOCALIP:$HGPORT/
5 > hg --verbose debugwireproto --peer raw http://$LOCALIP:$HGPORT/
@@ -60,27 +61,6 b' Restart server with support for HTTP v2 '
60 $ hg -R server serve -p $HGPORT -d --pid-file hg.pid
61 $ hg -R server serve -p $HGPORT -d --pid-file hg.pid
61 $ cat hg.pid > $DAEMON_PIDS
62 $ cat hg.pid > $DAEMON_PIDS
62
63
63 Request to read-only command works out of the box
64
65 $ send << EOF
66 > httprequest POST api/$HTTPV2/ro/customreadonly
67 > user-agent: test
68 > EOF
69 using raw connection to peer
70 s> POST /api/exp-http-v2-0001/ro/customreadonly HTTP/1.1\r\n
71 s> Accept-Encoding: identity\r\n
72 s> user-agent: test\r\n
73 s> host: $LOCALIP:$HGPORT\r\n (glob)
74 s> \r\n
75 s> makefile('rb', None)
76 s> HTTP/1.1 200 OK\r\n
77 s> Server: testing stub value\r\n
78 s> Date: $HTTP_DATE$\r\n
79 s> Content-Type: text/plain\r\n
80 s> Content-Length: 18\r\n
81 s> \r\n
82 s> ro/customreadonly\n
83
84 Request to unknown command yields 404
64 Request to unknown command yields 404
85
65
86 $ send << EOF
66 $ send << EOF
@@ -123,6 +103,100 b' GET to read-only command yields a 405'
123 s> \r\n
103 s> \r\n
124 s> commands require POST requests
104 s> commands require POST requests
125
105
106 Missing Accept header results in 406
107
108 $ send << EOF
109 > httprequest POST api/$HTTPV2/ro/customreadonly
110 > user-agent: test
111 > EOF
112 using raw connection to peer
113 s> POST /api/exp-http-v2-0001/ro/customreadonly HTTP/1.1\r\n
114 s> Accept-Encoding: identity\r\n
115 s> user-agent: test\r\n
116 s> host: $LOCALIP:$HGPORT\r\n (glob)
117 s> \r\n
118 s> makefile('rb', None)
119 s> HTTP/1.1 406 Not Acceptable\r\n
120 s> Server: testing stub value\r\n
121 s> Date: $HTTP_DATE$\r\n
122 s> Content-Type: text/plain\r\n
123 s> Content-Length: 72\r\n
124 s> \r\n
125 s> client MUST specify Accept header with value: application/mercurial-tbd\n
126
127 Bad Accept header results in 406
128
129 $ send << EOF
130 > httprequest POST api/$HTTPV2/ro/customreadonly
131 > accept: invalid
132 > user-agent: test
133 > EOF
134 using raw connection to peer
135 s> POST /api/exp-http-v2-0001/ro/customreadonly HTTP/1.1\r\n
136 s> Accept-Encoding: identity\r\n
137 s> accept: invalid\r\n
138 s> user-agent: test\r\n
139 s> host: $LOCALIP:$HGPORT\r\n (glob)
140 s> \r\n
141 s> makefile('rb', None)
142 s> HTTP/1.1 406 Not Acceptable\r\n
143 s> Server: testing stub value\r\n
144 s> Date: $HTTP_DATE$\r\n
145 s> Content-Type: text/plain\r\n
146 s> Content-Length: 72\r\n
147 s> \r\n
148 s> client MUST specify Accept header with value: application/mercurial-tbd\n
149
150 Bad Content-Type header results in 415
151
152 $ send << EOF
153 > httprequest POST api/$HTTPV2/ro/customreadonly
154 > accept: $MEDIATYPE
155 > user-agent: test
156 > content-type: badmedia
157 > EOF
158 using raw connection to peer
159 s> POST /api/exp-http-v2-0001/ro/customreadonly HTTP/1.1\r\n
160 s> Accept-Encoding: identity\r\n
161 s> accept: application/mercurial-tbd\r\n
162 s> content-type: badmedia\r\n
163 s> user-agent: test\r\n
164 s> host: $LOCALIP:$HGPORT\r\n (glob)
165 s> \r\n
166 s> makefile('rb', None)
167 s> HTTP/1.1 415 Unsupported Media Type\r\n
168 s> Server: testing stub value\r\n
169 s> Date: $HTTP_DATE$\r\n
170 s> Content-Type: text/plain\r\n
171 s> Content-Length: 75\r\n
172 s> \r\n
173 s> client MUST send Content-Type header with value: application/mercurial-tbd\n
174
175 Request to read-only command works out of the box
176
177 $ send << EOF
178 > httprequest POST api/$HTTPV2/ro/customreadonly
179 > accept: $MEDIATYPE
180 > content-type: $MEDIATYPE
181 > user-agent: test
182 > EOF
183 using raw connection to peer
184 s> POST /api/exp-http-v2-0001/ro/customreadonly HTTP/1.1\r\n
185 s> Accept-Encoding: identity\r\n
186 s> accept: application/mercurial-tbd\r\n
187 s> content-type: application/mercurial-tbd\r\n
188 s> user-agent: test\r\n
189 s> host: $LOCALIP:$HGPORT\r\n (glob)
190 s> \r\n
191 s> makefile('rb', None)
192 s> HTTP/1.1 200 OK\r\n
193 s> Server: testing stub value\r\n
194 s> Date: $HTTP_DATE$\r\n
195 s> Content-Type: text/plain\r\n
196 s> Content-Length: 18\r\n
197 s> \r\n
198 s> ro/customreadonly\n
199
126 Request to read-write command fails because server is read-only by default
200 Request to read-write command fails because server is read-only by default
127
201
128 GET to read-write request yields 405
202 GET to read-write request yields 405
@@ -207,10 +281,14 b' Authorized request for valid read-write '
207 $ send << EOF
281 $ send << EOF
208 > httprequest POST api/$HTTPV2/rw/customreadonly
282 > httprequest POST api/$HTTPV2/rw/customreadonly
209 > user-agent: test
283 > user-agent: test
284 > accept: $MEDIATYPE
285 > content-type: $MEDIATYPE
210 > EOF
286 > EOF
211 using raw connection to peer
287 using raw connection to peer
212 s> POST /api/exp-http-v2-0001/rw/customreadonly HTTP/1.1\r\n
288 s> POST /api/exp-http-v2-0001/rw/customreadonly HTTP/1.1\r\n
213 s> Accept-Encoding: identity\r\n
289 s> Accept-Encoding: identity\r\n
290 s> accept: application/mercurial-tbd\r\n
291 s> content-type: application/mercurial-tbd\r\n
214 s> user-agent: test\r\n
292 s> user-agent: test\r\n
215 s> host: $LOCALIP:$HGPORT\r\n (glob)
293 s> host: $LOCALIP:$HGPORT\r\n (glob)
216 s> \r\n
294 s> \r\n
@@ -228,10 +306,12 b' Authorized request for unknown command i'
228 $ send << EOF
306 $ send << EOF
229 > httprequest POST api/$HTTPV2/rw/badcommand
307 > httprequest POST api/$HTTPV2/rw/badcommand
230 > user-agent: test
308 > user-agent: test
309 > accept: $MEDIATYPE
231 > EOF
310 > EOF
232 using raw connection to peer
311 using raw connection to peer
233 s> POST /api/exp-http-v2-0001/rw/badcommand HTTP/1.1\r\n
312 s> POST /api/exp-http-v2-0001/rw/badcommand HTTP/1.1\r\n
234 s> Accept-Encoding: identity\r\n
313 s> Accept-Encoding: identity\r\n
314 s> accept: application/mercurial-tbd\r\n
235 s> user-agent: test\r\n
315 s> user-agent: test\r\n
236 s> host: $LOCALIP:$HGPORT\r\n (glob)
316 s> host: $LOCALIP:$HGPORT\r\n (glob)
237 s> \r\n
317 s> \r\n
General Comments 0
You need to be logged in to leave comments. Login now