diff options
author | Martin Panter <vadmium+py@gmail.com> | 2016-03-17 07:05:34 (GMT) |
---|---|---|
committer | Martin Panter <vadmium+py@gmail.com> | 2016-03-17 07:05:34 (GMT) |
commit | ec195fba5b4381b8b60fe8f9b400437f52b98371 (patch) | |
tree | 304d688d340ab4d28e190b18b6d9d4a752d4280a /Lib/http | |
parent | 82f04e2dfdd2bdfef5bd94f8d6615ac0a1f620b4 (diff) | |
parent | ce911c3fed7e6404fba7de3868b1000425984b1e (diff) | |
download | cpython-ec195fba5b4381b8b60fe8f9b400437f52b98371.zip cpython-ec195fba5b4381b8b60fe8f9b400437f52b98371.tar.gz cpython-ec195fba5b4381b8b60fe8f9b400437f52b98371.tar.bz2 |
Issue #26499: Merge HTTPResponse fix from 3.5
Diffstat (limited to 'Lib/http')
-rw-r--r-- | Lib/http/client.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/Lib/http/client.py b/Lib/http/client.py index 36e4e31..80b0dcb 100644 --- a/Lib/http/client.py +++ b/Lib/http/client.py @@ -640,6 +640,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: @@ -650,6 +652,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): @@ -667,9 +671,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): |