##// 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 return userpass + '@' + hostport
76 return userpass + '@' + hostport
77 return hostport
77 return hostport
78
78
79 class httpconnection(keepalive.HTTPConnection):
79 class httpsendfile(file):
80 # must be able to send big bundle as stream.
80 def __len__(self):
81 return os.fstat(self.fileno()).st_size
81
82
82 def send(self, data):
83 def _gen_sendfile(connection):
83 if isinstance(data, str):
84 def _sendfile(self, data):
84 keepalive.HTTPConnection.send(self, data)
85 # send a file
85 else:
86 if isinstance(data, httpsendfile):
86 # if auth required, some data sent twice, so rewind here
87 # if auth required, some data sent twice, so rewind here
87 data.seek(0)
88 data.seek(0)
88 for chunk in util.filechunkiter(data):
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 class basehttphandler(keepalive.HTTPHandler):
99 class basehttphandler(keepalive.HTTPHandler):
92 def http_open(self, req):
100 def http_open(self, req):
@@ -97,15 +105,7 b' if has_https:'
97 class httpsconnection(httplib.HTTPSConnection):
105 class httpsconnection(httplib.HTTPSConnection):
98 response_class = keepalive.HTTPResponse
106 response_class = keepalive.HTTPResponse
99 # must be able to send big bundle as stream.
107 # must be able to send big bundle as stream.
100
108 send = _gen_sendfile(httplib.HTTPSConnection)
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)
109
109
110 class httphandler(basehttphandler, urllib2.HTTPSHandler):
110 class httphandler(basehttphandler, urllib2.HTTPSHandler):
111 def https_open(self, req):
111 def https_open(self, req):
@@ -345,14 +345,12 b' class httprepository(remoterepository):'
345 break
345 break
346
346
347 tempname = changegroup.writebundle(cg, None, type)
347 tempname = changegroup.writebundle(cg, None, type)
348 fp = file(tempname, "rb")
348 fp = httpsendfile(tempname, "rb")
349 try:
349 try:
350 length = os.stat(tempname).st_size
351 try:
350 try:
352 rfp = self.do_cmd(
351 rfp = self.do_cmd(
353 'unbundle', data=fp,
352 'unbundle', data=fp,
354 headers={'content-length': str(length),
353 headers={'content-type': 'application/octet-stream'},
355 'content-type': 'application/octet-stream'},
356 heads=' '.join(map(hex, heads)))
354 heads=' '.join(map(hex, heads)))
357 try:
355 try:
358 ret = int(rfp.readline())
356 ret = int(rfp.readline())
General Comments 0
You need to be logged in to leave comments. Login now