Mercurial > hg-stable
changeset 28530:fd2acc5046f6
http: support sending hgargs via POST body instead of in GET or headers
narrowhg (for its narrow spec) and remotefilelog (for its large batch
requests) would like to be able to make requests with argument sets so
absurdly large that they blow out total request size limit on some
http servers. As a workaround, support stuffing args at the start
of the POST body.
We will probably want to leave this behavior off by default in servers
forever, because it makes the old "POSTs are only for writes"
assumption wrong, which might break some of the simpler authentication
configurations.
author | Augie Fackler <augie@google.com> |
---|---|
date | Fri, 11 Mar 2016 11:37:00 -0500 |
parents | 045cdf47851a |
children | fe79a5821e5a |
files | mercurial/hgweb/protocol.py mercurial/httppeer.py mercurial/wireproto.py tests/test-wireproto.t |
diffstat | 4 files changed, 81 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/hgweb/protocol.py Mon Mar 14 21:15:59 2016 -0400 +++ b/mercurial/hgweb/protocol.py Fri Mar 11 11:37:00 2016 -0500 @@ -45,6 +45,11 @@ return [data[k] for k in keys] def _args(self): args = self.req.form.copy() + postlen = int(self.req.env.get('HTTP_X_HGARGS_POST', 0)) + if postlen: + args.update(cgi.parse_qs( + self.req.read(postlen), keep_blank_values=True)) + return args chunks = [] i = 1 while True:
--- a/mercurial/httppeer.py Mon Mar 14 21:15:59 2016 -0400 +++ b/mercurial/httppeer.py Fri Mar 11 11:37:00 2016 -0500 @@ -97,7 +97,22 @@ self.ui.debug("sending %s command\n" % cmd) q = [('cmd', cmd)] headersize = 0 - if True: + # Important: don't use self.capable() here or else you end up + # with infinite recursion when trying to look up capabilities + # for the first time. + postargsok = self.caps is not None and 'httppostargs' in self.caps + # TODO: support for httppostargs when data is a file-like + # object rather than a basestring + canmungedata = not data or isinstance(data, basestring) + if postargsok and canmungedata: + strargs = urllib.urlencode(sorted(args.items())) + if strargs: + if not data: + data = strargs + elif isinstance(data, basestring): + data = strargs + data + headers['X-HgArgs-Post'] = len(strargs) + else: if len(args) > 0: httpheader = self.capable('httpheader') if httpheader:
--- a/mercurial/wireproto.py Mon Mar 14 21:15:59 2016 -0400 +++ b/mercurial/wireproto.py Fri Mar 11 11:37:00 2016 -0500 @@ -688,6 +688,8 @@ caps.append('unbundle=%s' % ','.join(changegroupmod.bundlepriority)) caps.append( 'httpheader=%d' % repo.ui.configint('server', 'maxhttpheaderlen', 1024)) + if repo.ui.configbool('experimental', 'httppostargs', False): + caps.append('httppostargs') return caps # If you are writing an extension and consider wrapping this function. Wrap
--- a/tests/test-wireproto.t Mon Mar 14 21:15:59 2016 -0400 +++ b/tests/test-wireproto.t Fri Mar 11 11:37:00 2016 -0500 @@ -19,7 +19,9 @@ HTTP: - $ hg serve -R repo -p $HGPORT -d --pid-file=hg1.pid -E error.log -A access.log + $ hg serve -R repo -p $HGPORT -d --pid-file=hg1.pid \ + > -E error.log -A access.log \ + > --config experimental.httppostargs=yes $ cat hg1.pid >> $DAEMON_PIDS $ hg debugwireargs http://localhost:$HGPORT/ un deux trois quatre @@ -37,6 +39,61 @@ $ cat error.log $ cat access.log * - - [*] "GET /?cmd=capabilities HTTP/1.1" 200 - (glob) + * - - [*] "POST /?cmd=debugwireargs HTTP/1.1" 200 - x-hgargs-post:39 (glob) + * - - [*] "POST /?cmd=debugwireargs HTTP/1.1" 200 - x-hgargs-post:39 (glob) + * - - [*] "GET /?cmd=capabilities HTTP/1.1" 200 - (glob) + * - - [*] "POST /?cmd=debugwireargs HTTP/1.1" 200 - x-hgargs-post:43 (glob) + * - - [*] "POST /?cmd=debugwireargs HTTP/1.1" 200 - x-hgargs-post:43 (glob) + * - - [*] "GET /?cmd=capabilities HTTP/1.1" 200 - (glob) + * - - [*] "POST /?cmd=debugwireargs HTTP/1.1" 200 - x-hgargs-post:27 (glob) + * - - [*] "POST /?cmd=debugwireargs HTTP/1.1" 200 - x-hgargs-post:27 (glob) + * - - [*] "GET /?cmd=capabilities HTTP/1.1" 200 - (glob) + * - - [*] "POST /?cmd=debugwireargs HTTP/1.1" 200 - x-hgargs-post:17 (glob) + * - - [*] "POST /?cmd=debugwireargs HTTP/1.1" 200 - x-hgargs-post:17 (glob) + * - - [*] "GET /?cmd=capabilities HTTP/1.1" 200 - (glob) + * - - [*] "POST /?cmd=debugwireargs HTTP/1.1" 200 - x-hgargs-post:17 (glob) + * - - [*] "POST /?cmd=debugwireargs HTTP/1.1" 200 - x-hgargs-post:17 (glob) + * - - [*] "GET /?cmd=capabilities HTTP/1.1" 200 - (glob) + * - - [*] "POST /?cmd=debugwireargs HTTP/1.1" 200 - x-hgargs-post:1033 (glob) + * - - [*] "POST /?cmd=debugwireargs HTTP/1.1" 200 - x-hgargs-post:1033 (glob) + +HTTP without args-in-POST: + $ hg serve -R repo -p $HGPORT1 -d --pid-file=hg1.pid -E error.log -A access.log + $ cat hg1.pid >> $DAEMON_PIDS + + $ hg debugwireargs http://localhost:$HGPORT1/ un deux trois quatre + un deux trois quatre None + $ hg debugwireargs http://localhost:$HGPORT1/ \ un deux trois\ qu\ \ atre + un deux trois qu atre None + $ hg debugwireargs http://localhost:$HGPORT1/ eins zwei --four vier + eins zwei None vier None + $ hg debugwireargs http://localhost:$HGPORT1/ eins zwei + eins zwei None None None + $ hg debugwireargs http://localhost:$HGPORT1/ eins zwei --five fuenf + eins zwei None None None + $ hg debugwireargs http://localhost:$HGPORT1/ un deux trois onethousandcharactersxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx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xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx None + $ cat error.log + $ cat access.log + * - - [*] "GET /?cmd=capabilities HTTP/1.1" 200 - (glob) + * - - [*] "POST /?cmd=debugwireargs HTTP/1.1" 200 - x-hgargs-post:39 (glob) + * - - [*] "POST /?cmd=debugwireargs HTTP/1.1" 200 - x-hgargs-post:39 (glob) + * - - [*] "GET /?cmd=capabilities HTTP/1.1" 200 - (glob) + * - - [*] "POST /?cmd=debugwireargs HTTP/1.1" 200 - x-hgargs-post:43 (glob) + * - - [*] "POST /?cmd=debugwireargs HTTP/1.1" 200 - x-hgargs-post:43 (glob) + * - - [*] "GET /?cmd=capabilities HTTP/1.1" 200 - (glob) + * - - [*] "POST /?cmd=debugwireargs HTTP/1.1" 200 - x-hgargs-post:27 (glob) + * - - [*] "POST /?cmd=debugwireargs HTTP/1.1" 200 - x-hgargs-post:27 (glob) + * - - [*] "GET /?cmd=capabilities HTTP/1.1" 200 - (glob) + * - - [*] "POST /?cmd=debugwireargs HTTP/1.1" 200 - x-hgargs-post:17 (glob) + * - - [*] "POST /?cmd=debugwireargs HTTP/1.1" 200 - x-hgargs-post:17 (glob) + * - - [*] "GET /?cmd=capabilities HTTP/1.1" 200 - (glob) + * - - [*] "POST /?cmd=debugwireargs HTTP/1.1" 200 - x-hgargs-post:17 (glob) + * - - [*] "POST /?cmd=debugwireargs HTTP/1.1" 200 - x-hgargs-post:17 (glob) + * - - [*] "GET /?cmd=capabilities HTTP/1.1" 200 - (glob) + * - - [*] "POST /?cmd=debugwireargs HTTP/1.1" 200 - x-hgargs-post:1033 (glob) + * - - [*] "POST /?cmd=debugwireargs HTTP/1.1" 200 - x-hgargs-post:1033 (glob) + * - - [*] "GET /?cmd=capabilities HTTP/1.1" 200 - (glob) * - - [*] "GET /?cmd=debugwireargs HTTP/1.1" 200 - x-hgarg-1:four=quatre&one=un&three=trois&two=deux (glob) * - - [*] "GET /?cmd=debugwireargs HTTP/1.1" 200 - x-hgarg-1:four=quatre&one=un&three=trois&two=deux (glob) * - - [*] "GET /?cmd=capabilities HTTP/1.1" 200 - (glob)