comparison mercurial/httprepo.py @ 15152:94b200a11cf7 stable

http: handle push of bundles > 2 GB again (issue3017) It was very elegant that httpsendfile implemented __len__ like a string. It was however also dangerous because that protocol can't handle sizes bigger than 2 GB. Mercurial tried to work around that, but it turned out to be too easy to introduce new errors in this area. With this change __len__ is no longer implemented at all and the code will work the same way for short and long posts.
author Mads Kiilerich <mads@kiilerich.com>
date Wed, 21 Sep 2011 22:52:00 +0200
parents 4f39610996fa
children 85322c19c831
comparison
equal deleted inserted replaced
15095:ec222a29bdf0 15152:94b200a11cf7
72 72
73 def _callstream(self, cmd, **args): 73 def _callstream(self, cmd, **args):
74 if cmd == 'pushkey': 74 if cmd == 'pushkey':
75 args['data'] = '' 75 args['data'] = ''
76 data = args.pop('data', None) 76 data = args.pop('data', None)
77 size = 0
78 if util.safehasattr(data, 'length'):
79 size = data.length
80 elif data is not None:
81 size = len(data)
77 headers = args.pop('headers', {}) 82 headers = args.pop('headers', {})
78 83
79 if data and self.ui.configbool('ui', 'usehttp2', False): 84 if size and self.ui.configbool('ui', 'usehttp2', False):
80 headers['Expect'] = '100-Continue' 85 headers['Expect'] = '100-Continue'
81 headers['X-HgHttp2'] = '1' 86 headers['X-HgHttp2'] = '1'
82 87
83 self.ui.debug("sending %s command\n" % cmd) 88 self.ui.debug("sending %s command\n" % cmd)
84 q = [('cmd', cmd)] 89 q = [('cmd', cmd)]
103 q += sorted(args.items()) 108 q += sorted(args.items())
104 qs = '?%s' % urllib.urlencode(q) 109 qs = '?%s' % urllib.urlencode(q)
105 cu = "%s%s" % (self._url, qs) 110 cu = "%s%s" % (self._url, qs)
106 req = urllib2.Request(cu, data, headers) 111 req = urllib2.Request(cu, data, headers)
107 if data is not None: 112 if data is not None:
108 # len(data) is broken if data doesn't fit into Py_ssize_t
109 # add the header ourself to avoid OverflowError
110 size = data.__len__()
111 self.ui.debug("sending %s bytes\n" % size) 113 self.ui.debug("sending %s bytes\n" % size)
112 req.add_unredirected_header('Content-Length', '%d' % size) 114 req.add_unredirected_header('Content-Length', '%d' % size)
113 try: 115 try:
114 resp = self.urlopener.open(req) 116 resp = self.urlopener.open(req)
115 except urllib2.HTTPError, inst: 117 except urllib2.HTTPError, inst: