Mercurial > public > mercurial-scm > hg
comparison mercurial/httppeer.py @ 36218:e4ccd7a69f77
httppeer: change logic around argument handling
The code to process arguments only makes sense if there are
arguments. So change an "else" to "elif args", remove an
"if" that isn't necessary, and add some docs for good measure.
Differential Revision: https://phab.mercurial-scm.org/D2214
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Thu, 01 Feb 2018 19:32:42 -0800 |
parents | 197d10e157ce |
children | a463f375f021 |
comparison
equal
deleted
inserted
replaced
36217:1ee1a42bfdae | 36218:e4ccd7a69f77 |
---|---|
250 varyheaders = [] | 250 varyheaders = [] |
251 # Important: don't use self.capable() here or else you end up | 251 # Important: don't use self.capable() here or else you end up |
252 # with infinite recursion when trying to look up capabilities | 252 # with infinite recursion when trying to look up capabilities |
253 # for the first time. | 253 # for the first time. |
254 postargsok = self._caps is not None and 'httppostargs' in self._caps | 254 postargsok = self._caps is not None and 'httppostargs' in self._caps |
255 | |
256 # Send arguments via POST. | |
255 if postargsok and args: | 257 if postargsok and args: |
256 strargs = urlreq.urlencode(sorted(args.items())) | 258 strargs = urlreq.urlencode(sorted(args.items())) |
257 if not data: | 259 if not data: |
258 data = strargs | 260 data = strargs |
259 else: | 261 else: |
263 data = i | 265 data = i |
264 argsio = io.BytesIO(strargs) | 266 argsio = io.BytesIO(strargs) |
265 argsio.length = len(strargs) | 267 argsio.length = len(strargs) |
266 data = _multifile(argsio, data) | 268 data = _multifile(argsio, data) |
267 headers[r'X-HgArgs-Post'] = len(strargs) | 269 headers[r'X-HgArgs-Post'] = len(strargs) |
268 else: | 270 elif args: |
269 if len(args) > 0: | 271 # Calling self.capable() can infinite loop if we are calling |
270 httpheader = self.capable('httpheader') | 272 # "capabilities". But that command should never accept wire |
271 if httpheader: | 273 # protocol arguments. So this should never happen. |
272 headersize = int(httpheader.split(',', 1)[0]) | 274 assert cmd != 'capabilities' |
275 httpheader = self.capable('httpheader') | |
276 if httpheader: | |
277 headersize = int(httpheader.split(',', 1)[0]) | |
278 | |
279 # Send arguments via HTTP headers. | |
273 if headersize > 0: | 280 if headersize > 0: |
274 # The headers can typically carry more data than the URL. | 281 # The headers can typically carry more data than the URL. |
275 encargs = urlreq.urlencode(sorted(args.items())) | 282 encargs = urlreq.urlencode(sorted(args.items())) |
276 for header, value in encodevalueinheaders(encargs, 'X-HgArg', | 283 for header, value in encodevalueinheaders(encargs, 'X-HgArg', |
277 headersize): | 284 headersize): |
278 headers[header] = value | 285 headers[header] = value |
279 varyheaders.append(header) | 286 varyheaders.append(header) |
287 # Send arguments via query string (Mercurial <1.9). | |
280 else: | 288 else: |
281 q += sorted(args.items()) | 289 q += sorted(args.items()) |
290 | |
282 qs = '?%s' % urlreq.urlencode(q) | 291 qs = '?%s' % urlreq.urlencode(q) |
283 cu = "%s%s" % (self._url, qs) | 292 cu = "%s%s" % (self._url, qs) |
284 size = 0 | 293 size = 0 |
285 if util.safehasattr(data, 'length'): | 294 if util.safehasattr(data, 'length'): |
286 size = data.length | 295 size = data.length |