From 6ee5a944fa9bc70ac10a0b49e39abce9f7d8b5f4 Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Fri, 24 Jun 2016 07:53:05 -0500 Subject: Fix chunked transfer-encoding with preload_content When we implemented our own chunked transfer-encoding logic, we broke the use case (that we did not anticipate) of people not specifying preload_content=False to stream their data. This provides a fix, sans tests, for that use case. Closes gh-907 --- urllib3/response.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/urllib3/response.py b/urllib3/response.py index 55679032..a896cb7f 100644 --- a/urllib3/response.py +++ b/urllib3/response.py @@ -133,7 +133,7 @@ class HTTPResponse(io.IOBase): self.chunked = True # If requested, preload the body. - if preload_content and not self._body: + if preload_content and not (self._body or self.chunked): self._body = self.read(decode_content=decode_content) def get_redirect_location(self): @@ -485,6 +485,8 @@ class HTTPResponse(io.IOBase): If True, will attempt to decode the body based on the 'content-encoding' header. """ + if self._body: + return self._init_decoder() # FIXME: Rewrite this method and make it a class with a better structured logic. if not self.chunked: -- cgit v1.2.1