Mercurial > hg-stable
changeset 36256: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 | 1ee1a42bfdae |
children | a463f375f021 |
files | mercurial/httppeer.py |
diffstat | 1 files changed, 14 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/httppeer.py Mon Feb 12 16:35:06 2018 -0800 +++ b/mercurial/httppeer.py Thu Feb 01 19:32:42 2018 -0800 @@ -252,6 +252,8 @@ # with infinite recursion when trying to look up capabilities # for the first time. postargsok = self._caps is not None and 'httppostargs' in self._caps + + # Send arguments via POST. if postargsok and args: strargs = urlreq.urlencode(sorted(args.items())) if not data: @@ -265,11 +267,16 @@ argsio.length = len(strargs) data = _multifile(argsio, data) headers[r'X-HgArgs-Post'] = len(strargs) - else: - if len(args) > 0: - httpheader = self.capable('httpheader') - if httpheader: - headersize = int(httpheader.split(',', 1)[0]) + elif args: + # Calling self.capable() can infinite loop if we are calling + # "capabilities". But that command should never accept wire + # protocol arguments. So this should never happen. + assert cmd != 'capabilities' + httpheader = self.capable('httpheader') + if httpheader: + headersize = int(httpheader.split(',', 1)[0]) + + # Send arguments via HTTP headers. if headersize > 0: # The headers can typically carry more data than the URL. encargs = urlreq.urlencode(sorted(args.items())) @@ -277,8 +284,10 @@ headersize): headers[header] = value varyheaders.append(header) + # Send arguments via query string (Mercurial <1.9). else: q += sorted(args.items()) + qs = '?%s' % urlreq.urlencode(q) cu = "%s%s" % (self._url, qs) size = 0