summaryrefslogtreecommitdiffstats
path: root/Lib/http
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2013-02-02 22:04:56 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2013-02-02 22:04:56 (GMT)
commit6a35e18161c4d06015aeb79c951df04bcea9ca9a (patch)
tree3aa2bc2803418677010f6923b50c80494f20b22c /Lib/http
parentc27bcbf86316fd45180a8b881c55ed3ac7f9fa50 (diff)
parentbeec61ae4e811f55f58d0197c8af994e252ab9ae (diff)
downloadcpython-6a35e18161c4d06015aeb79c951df04bcea9ca9a.zip
cpython-6a35e18161c4d06015aeb79c951df04bcea9ca9a.tar.gz
cpython-6a35e18161c4d06015aeb79c951df04bcea9ca9a.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.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/Lib/http/client.py b/Lib/http/client.py
index 6a4496f..62d9cff 100644
--- a/Lib/http/client.py
+++ b/Lib/http/client.py
@@ -507,7 +507,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
@@ -532,13 +536,14 @@ class HTTPResponse(io.RawIOBase):
# connection, and the user is reading more bytes than will be provided
# (for example, reading in 1k chunks)
n = self.fp.readinto(b)
- if self.length is not None:
+ if not n:
+ # Ideally, we would raise IncompleteRead if the content-length
+ # wasn't satisfied, but it might break compatibility.
+ self.close()
+ elif self.length is not None:
self.length -= n
if not self.length:
self.close()
- else:
- if not n:
- self.close()
return n
def _read_next_chunk_size(self):