Patchwork [2,of,5,postargs] httppeer: move size computation later in _callstream

login
register
mail settings
Submitter Augie Fackler
Date March 11, 2016, 4:55 p.m.
Message ID <b93d91a613340e102a32.1457715313@arthedain.pit.corp.google.com>
Download mbox | patch
Permalink /patch/13794/
State Accepted
Delegated to: Martin von Zweigbergk
Headers show

Comments

Augie Fackler - March 11, 2016, 4:55 p.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1457713572 18000
#      Fri Mar 11 11:26:12 2016 -0500
# Node ID b93d91a613340e102a3241d22cae7967d973de54
# Parent  4c628e9d4647100d2beed4aeb53dd01e50bf4770
# EXP-Topic batch
httppeer: move size computation later in _callstream

A future change will alter some of the arg-sending logic in a way that matters
for request body size. Centralizing the logic now will make later patches
easier to review.

Patch

diff --git a/mercurial/httppeer.py b/mercurial/httppeer.py
--- a/mercurial/httppeer.py
+++ b/mercurial/httppeer.py
@@ -92,19 +92,7 @@  class httppeer(wireproto.wirepeer):
         if cmd == 'pushkey':
             args['data'] = ''
         data = args.pop('data', None)
-        size = 0
-        if util.safehasattr(data, 'length'):
-            size = data.length
-        elif data is not None:
-            size = len(data)
         headers = args.pop('headers', {})
-        if data is not None and 'Content-Type' not in headers:
-            headers['Content-Type'] = 'application/mercurial-0.1'
-
-
-        if size and self.ui.configbool('ui', 'usehttp2', False):
-            headers['Expect'] = '100-Continue'
-            headers['X-HgHttp2'] = '1'
 
         self.ui.debug("sending %s command\n" % cmd)
         q = [('cmd', cmd)]
@@ -129,6 +117,16 @@  class httppeer(wireproto.wirepeer):
             q += sorted(args.items())
         qs = '?%s' % urllib.urlencode(q)
         cu = "%s%s" % (self._url, qs)
+        size = 0
+        if util.safehasattr(data, 'length'):
+            size = data.length
+        elif data is not None:
+            size = len(data)
+        if size and self.ui.configbool('ui', 'usehttp2', False):
+            headers['Expect'] = '100-Continue'
+            headers['X-HgHttp2'] = '1'
+        if data is not None and 'Content-Type' not in headers:
+            headers['Content-Type'] = 'application/mercurial-0.1'
         req = self.requestbuilder(cu, data, headers)
         if data is not None:
             self.ui.debug("sending %s bytes\n" % size)