diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2013-02-02 21:49:34 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2013-02-02 21:49:34 (GMT) |
commit | beec61ae4e811f55f58d0197c8af994e252ab9ae (patch) | |
tree | 3a5a7b021457780e1f020297404f677e94ffc3c9 /Lib/http | |
parent | 637525718873f9c6571078e0201523438b17d341 (diff) | |
download | cpython-beec61ae4e811f55f58d0197c8af994e252ab9ae.zip cpython-beec61ae4e811f55f58d0197c8af994e252ab9ae.tar.gz cpython-beec61ae4e811f55f58d0197c8af994e252ab9ae.tar.bz2 |
Issue #15633: httplib.HTTPResponse is now mark closed when the server sends less than the advertised Content-Length.
Diffstat (limited to 'Lib/http')
-rw-r--r-- | Lib/http/client.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/Lib/http/client.py b/Lib/http/client.py index 4d93b93..36528da 100644 --- a/Lib/http/client.py +++ b/Lib/http/client.py @@ -493,7 +493,11 @@ class HTTPResponse(io.RawIOBase): 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 @@ class HTTPResponse(io.RawIOBase): # 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: |