Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit def9d2a

Browse files
committed
Fix for SF bug 988120 via patch 1061941.
If read() returned less than the number of bytes request, the full amount was subtracted from length instead of the actually read amount.
1 parent f164322 commit def9d2a

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

Lib/httplib.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,23 +457,25 @@ def read(self, amt=None):
457457

458458
if amt is None:
459459
# unbounded read
460-
if self.will_close:
460+
if self.length is None:
461461
s = self.fp.read()
462462
else:
463463
s = self._safe_read(self.length)
464+
self.length = 0
464465
self.close() # we read everything
465466
return s
466467

467468
if self.length is not None:
468469
if amt > self.length:
469470
# clip the read to the "end of response"
470471
amt = self.length
471-
self.length -= amt
472472

473473
# we do not use _safe_read() here because this may be a .will_close
474474
# connection, and the user is reading more bytes than will be provided
475475
# (for example, reading in 1k chunks)
476476
s = self.fp.read(amt)
477+
if self.length is not None:
478+
self.length -= len(s)
477479

478480
return s
479481

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ Jiba
302302
Orjan Johansen
303303
Simon Johnston
304304
Richard Jones
305+
Irmen de Jong
305306
Lucas de Jonge
306307
Jens B. Jorgensen
307308
John Jorgensen

0 commit comments

Comments
 (0)