Mercurial > hg
comparison mercurial/httppeer.py @ 28484:da6f713ab480
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.
author | Augie Fackler <augie@google.com> |
---|---|
date | Fri, 11 Mar 2016 11:26:12 -0500 |
parents | 6f38ec428a19 |
children | d3893900f6c8 |
comparison
equal
deleted
inserted
replaced
28483:6f38ec428a19 | 28484:da6f713ab480 |
---|---|
90 | 90 |
91 def _callstream(self, cmd, **args): | 91 def _callstream(self, cmd, **args): |
92 if cmd == 'pushkey': | 92 if cmd == 'pushkey': |
93 args['data'] = '' | 93 args['data'] = '' |
94 data = args.pop('data', None) | 94 data = args.pop('data', None) |
95 size = 0 | |
96 if util.safehasattr(data, 'length'): | |
97 size = data.length | |
98 elif data is not None: | |
99 size = len(data) | |
100 headers = args.pop('headers', {}) | 95 headers = args.pop('headers', {}) |
101 if data is not None and 'Content-Type' not in headers: | |
102 headers['Content-Type'] = 'application/mercurial-0.1' | |
103 | |
104 | |
105 if size and self.ui.configbool('ui', 'usehttp2', False): | |
106 headers['Expect'] = '100-Continue' | |
107 headers['X-HgHttp2'] = '1' | |
108 | 96 |
109 self.ui.debug("sending %s command\n" % cmd) | 97 self.ui.debug("sending %s command\n" % cmd) |
110 q = [('cmd', cmd)] | 98 q = [('cmd', cmd)] |
111 headersize = 0 | 99 headersize = 0 |
112 if len(args) > 0: | 100 if len(args) > 0: |
127 headers['Vary'] = ','.join(varyheaders) | 115 headers['Vary'] = ','.join(varyheaders) |
128 else: | 116 else: |
129 q += sorted(args.items()) | 117 q += sorted(args.items()) |
130 qs = '?%s' % urllib.urlencode(q) | 118 qs = '?%s' % urllib.urlencode(q) |
131 cu = "%s%s" % (self._url, qs) | 119 cu = "%s%s" % (self._url, qs) |
120 size = 0 | |
121 if util.safehasattr(data, 'length'): | |
122 size = data.length | |
123 elif data is not None: | |
124 size = len(data) | |
125 if size and self.ui.configbool('ui', 'usehttp2', False): | |
126 headers['Expect'] = '100-Continue' | |
127 headers['X-HgHttp2'] = '1' | |
128 if data is not None and 'Content-Type' not in headers: | |
129 headers['Content-Type'] = 'application/mercurial-0.1' | |
132 req = self.requestbuilder(cu, data, headers) | 130 req = self.requestbuilder(cu, data, headers) |
133 if data is not None: | 131 if data is not None: |
134 self.ui.debug("sending %s bytes\n" % size) | 132 self.ui.debug("sending %s bytes\n" % size) |
135 req.add_unredirected_header('Content-Length', '%d' % size) | 133 req.add_unredirected_header('Content-Length', '%d' % size) |
136 try: | 134 try: |