##// END OF EJS Templates
keepalive: don't concatenate strings when reading chunked transfer...
Gregory Szorc -
r30686:8352c42a default
parent child Browse files
Show More
@@ -399,10 +399,8 b' class HTTPResponse(httplib.HTTPResponse)'
399 399 # stolen from Python SVN #68532 to fix issue1088
400 400 def _read_chunked(self, amt):
401 401 chunk_left = self.chunk_left
402 value = ''
402 parts = []
403 403
404 # XXX This accumulates chunks by repeated string concatenation,
405 # which is not efficient as the number or size of chunks gets big.
406 404 while True:
407 405 if chunk_left is None:
408 406 line = self.fp.readline()
@@ -415,22 +413,22 b' class HTTPResponse(httplib.HTTPResponse)'
415 413 # close the connection as protocol synchronization is
416 414 # probably lost
417 415 self.close()
418 raise httplib.IncompleteRead(value)
416 raise httplib.IncompleteRead(''.join(parts))
419 417 if chunk_left == 0:
420 418 break
421 419 if amt is None:
422 value += self._safe_read(chunk_left)
420 parts.append(self._safe_read(chunk_left))
423 421 elif amt < chunk_left:
424 value += self._safe_read(amt)
422 parts.append(self._safe_read(amt))
425 423 self.chunk_left = chunk_left - amt
426 return value
424 return ''.join(parts)
427 425 elif amt == chunk_left:
428 value += self._safe_read(amt)
426 parts.append(self._safe_read(amt))
429 427 self._safe_read(2) # toss the CRLF at the end of the chunk
430 428 self.chunk_left = None
431 return value
429 return ''.join(parts)
432 430 else:
433 value += self._safe_read(chunk_left)
431 parts.append(self._safe_read(chunk_left))
434 432 amt -= chunk_left
435 433
436 434 # we read the whole chunk, get another
@@ -451,7 +449,7 b' class HTTPResponse(httplib.HTTPResponse)'
451 449 # we read everything; close the "file"
452 450 self.close()
453 451
454 return value
452 return ''.join(parts)
455 453
456 454 def readline(self, limit=-1):
457 455 i = self._rbuf.find('\n')
General Comments 0
You need to be logged in to leave comments. Login now