httppeer: move size computation later in _callstream
authorAugie Fackler <augie@google.com>
Fri, 11 Mar 2016 11:26:12 -0500
changeset 28484 da6f713ab480
parent 28483 6f38ec428a19
child 28485 d3893900f6c8
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.
mercurial/httppeer.py
--- a/mercurial/httppeer.py	Fri Mar 11 11:24:50 2016 -0500
+++ b/mercurial/httppeer.py	Fri Mar 11 11:26:12 2016 -0500
@@ -92,19 +92,7 @@
         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 @@
             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)