summaryrefslogtreecommitdiffstats
path: root/Lib/http
diff options
context:
space:
mode:
authorMartin Panter <vadmium+py@gmail.com>2016-03-17 06:42:48 (GMT)
committerMartin Panter <vadmium+py@gmail.com>2016-03-17 06:42:48 (GMT)
commitce911c3fed7e6404fba7de3868b1000425984b1e (patch)
tree3c59e3e10f631a567a18c23b27dfe68f2f9e3484 /Lib/http
parent9528334e16abf1673edcfadf7007f55a864079b7 (diff)
downloadcpython-ce911c3fed7e6404fba7de3868b1000425984b1e.zip
cpython-ce911c3fed7e6404fba7de3868b1000425984b1e.tar.gz
cpython-ce911c3fed7e6404fba7de3868b1000425984b1e.tar.bz2
Issue #26499: Fixes to HTTPResponse.readline() and read1(), by Silent Ghost
Diffstat (limited to 'Lib/http')
-rw-r--r--Lib/http/client.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/Lib/http/client.py b/Lib/http/client.py
index 24231b5..2d6e07b 100644
--- a/Lib/http/client.py
+++ b/Lib/http/client.py
@@ -635,6 +635,8 @@ class HTTPResponse(io.BufferedIOBase):
return b""
if self.chunked:
return self._read1_chunked(n)
+ if self.length is not None and (n < 0 or n > self.length):
+ n = self.length
try:
result = self.fp.read1(n)
except ValueError:
@@ -645,6 +647,8 @@ class HTTPResponse(io.BufferedIOBase):
result = self.fp.read1(16*1024)
if not result and n:
self._close_conn()
+ elif self.length is not None:
+ self.length -= len(result)
return result
def peek(self, n=-1):
@@ -662,9 +666,13 @@ class HTTPResponse(io.BufferedIOBase):
if self.chunked:
# Fallback to IOBase readline which uses peek() and read()
return super().readline(limit)
+ if self.length is not None and (limit < 0 or limit > self.length):
+ limit = self.length
result = self.fp.readline(limit)
if not result and limit:
self._close_conn()
+ elif self.length is not None:
+ self.length -= len(result)
return result
def _read1_chunked(self, n):