Mercurial > cpython-lru_cache-weakref
diff Lib/http/client.py @ 81950:03c536afeb7e 3.2
Issue #15633: httplib.HTTPResponse is now mark closed when the server sends less than the advertised Content-Length.
| author | Antoine Pitrou <solipsis@pitrou.net> |
|---|---|
| date | Sat, 02 Feb 2013 22:49:34 +0100 |
| parents | b47d342c449b |
| children | 41d2c18abbf4 7d504068bc58 |
line wrap: on
line diff
--- a/Lib/http/client.py Sat Feb 02 20:05:11 2013 +0100 +++ b/Lib/http/client.py Sat Feb 02 22:49:34 2013 +0100 @@ -493,7 +493,11 @@ 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 @@ -507,6 +511,10 @@ # 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:
