diff options
Diffstat (limited to 'Lib/httplib.py')
-rw-r--r-- | Lib/httplib.py | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/Lib/httplib.py b/Lib/httplib.py index 9d11d04..5c919d2 100644 --- a/Lib/httplib.py +++ b/Lib/httplib.py @@ -547,7 +547,11 @@ class HTTPResponse: if self.length is None: s = self.fp.read() else: - s = self._safe_read(self.length) + try: + s = self._safe_read(self.length) + except IncompleteRead: + self.close() + raise self.length = 0 self.close() # we read everything return s @@ -561,13 +565,14 @@ class HTTPResponse: # connection, and the user is reading more bytes than will be provided # (for example, reading in 1k chunks) s = self.fp.read(amt) + if not s: + # Ideally, we would raise IncompleteRead if the content-length + # wasn't satisfied, but it might break compatibility. + self.close() if self.length is not None: self.length -= len(s) if not self.length: self.close() - else: - if not s: - self.close() return s |