##// END OF EJS Templates
Subclass file with a __len__ method instead of setting Content-length...
Benoit Boissinot -
r4025:d8b3edf8 default
parent child Browse files
Show More
@@ -76,17 +76,25 b' def netlocunsplit(host, port, user=None,'
76 76 return userpass + '@' + hostport
77 77 return hostport
78 78
79 class httpconnection(keepalive.HTTPConnection):
80 # must be able to send big bundle as stream.
79 class httpsendfile(file):
80 def __len__(self):
81 return os.fstat(self.fileno()).st_size
81 82
82 def send(self, data):
83 if isinstance(data, str):
84 keepalive.HTTPConnection.send(self, data)
85 else:
83 def _gen_sendfile(connection):
84 def _sendfile(self, data):
85 # send a file
86 if isinstance(data, httpsendfile):
86 87 # if auth required, some data sent twice, so rewind here
87 88 data.seek(0)
88 89 for chunk in util.filechunkiter(data):
89 keepalive.HTTPConnection.send(self, chunk)
90 connection.send(self, chunk)
91 else:
92 connection.send(self, data)
93 return _sendfile
94
95 class httpconnection(keepalive.HTTPConnection):
96 # must be able to send big bundle as stream.
97 send = _gen_sendfile(keepalive.HTTPConnection)
90 98
91 99 class basehttphandler(keepalive.HTTPHandler):
92 100 def http_open(self, req):
@@ -97,15 +105,7 b' if has_https:'
97 105 class httpsconnection(httplib.HTTPSConnection):
98 106 response_class = keepalive.HTTPResponse
99 107 # must be able to send big bundle as stream.
100
101 def send(self, data):
102 if isinstance(data, str):
103 httplib.HTTPSConnection.send(self, data)
104 else:
105 # if auth required, some data sent twice, so rewind here
106 data.seek(0)
107 for chunk in util.filechunkiter(data):
108 httplib.HTTPSConnection.send(self, chunk)
108 send = _gen_sendfile(httplib.HTTPSConnection)
109 109
110 110 class httphandler(basehttphandler, urllib2.HTTPSHandler):
111 111 def https_open(self, req):
@@ -345,14 +345,12 b' class httprepository(remoterepository):'
345 345 break
346 346
347 347 tempname = changegroup.writebundle(cg, None, type)
348 fp = file(tempname, "rb")
348 fp = httpsendfile(tempname, "rb")
349 349 try:
350 length = os.stat(tempname).st_size
351 350 try:
352 351 rfp = self.do_cmd(
353 352 'unbundle', data=fp,
354 headers={'content-length': str(length),
355 'content-type': 'application/octet-stream'},
353 headers={'content-type': 'application/octet-stream'},
356 354 heads=' '.join(map(hex, heads)))
357 355 try:
358 356 ret = int(rfp.readline())
General Comments 0
You need to be logged in to leave comments. Login now