summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Cordasco <graffatcolmingov@gmail.com>2015-04-24 12:12:56 -0500
committerIan Cordasco <graffatcolmingov@gmail.com>2015-04-24 12:17:03 -0500
commitbdabaafdb0ad707aff42a79c03842b6a090da485 (patch)
treeb3549b2a3b73c8be5a8ab63a0ad051d67f207f6d
parent23060d67836f71a838e68d6f3889baacf6a530c9 (diff)
downloadurllib3-bdabaafdb0ad707aff42a79c03842b6a090da485.tar.gz
Reorder logic of _update_chunk_length
By bailing out of the method early if the chunk_size is not None, we can make the rest of the method easier to read.
-rw-r--r--urllib3/response.py23
1 files changed, 10 insertions, 13 deletions
diff --git a/urllib3/response.py b/urllib3/response.py
index 191dc558..88d823dc 100644
--- a/urllib3/response.py
+++ b/urllib3/response.py
@@ -389,19 +389,16 @@ class HTTPResponse(io.IOBase):
def _get_next_chunk(self):
# First, we'll figure out length of a chunk and then
# we'll try to read it from socket.
- if self.chunk_left is None:
- line = self._fp.fp.readline()
- line = line.decode()
- # See RFC 7230: Chunked Transfer Coding.
- i = line.find(';')
- if i >= 0:
- line = line[:i] # Strip chunk-extensions.
- try:
- self.chunk_left = int(line, 16)
- except ValueError:
- # Invalid chunked protocol response, abort.
- self.close()
- raise httplib.IncompleteRead(line)
+ if self.chunk_left is not None:
+ return
+ line = self._fp.fp.readline()
+ line = line.split(b';', 1)[0]
+ try:
+ self.chunk_left = int(line, 16)
+ except ValueError:
+ # Invalid chunked protocol response, abort.
+ self.close()
+ raise httplib.IncompleteRead(line)
def _handle_chunk(self, amt):
returned_chunk = None