Always honor decode_unicode, even when _content is present.
authorJason R. Coombs <jaraco@jaraco.com>
Tue, 4 Mar 2014 21:33:40 +0000 (16:33 -0500)
committerJason R. Coombs <jaraco@jaraco.com>
Tue, 4 Mar 2014 21:33:40 +0000 (16:33 -0500)
--HG--
extra : amend_source : 25977a1227b163d49bf2e1aec6aa448e5cd3be8a

requests/models.py

index 682cd9e15b7fd9db31fdf3e76bfee6e35fa57855..c55e6ea7ecba49332f370e9b9ab6ea8730bb0b2f 100644 (file)
@@ -621,10 +621,6 @@ class Response(object):
         If decode_unicode is True, content will be decoded using the best
         available encoding based on the response.
         """
-        if self._content_consumed:
-            # simulate reading small chunks of the content
-            return iter_slices(self._content, chunk_size)
-
         def generate():
             try:
                 # Special case for urllib3.
@@ -645,12 +641,17 @@ class Response(object):
 
             self._content_consumed = True
 
-        gen = generate()
+        # simulate reading small chunks of the content
+        reused_chunks = iter_slices(self._content, chunk_size)
+
+        stream_chunks = generate()
+
+        chunks = reused_chunks if self._content_consumed else stream_chunks
 
         if decode_unicode:
-            gen = stream_decode_response_unicode(gen, self)
+            chunks = stream_decode_response_unicode(chunks, self)
 
-        return gen
+        return chunks
 
     def iter_lines(self, chunk_size=ITER_CHUNK_SIZE, decode_unicode=None):
         """Iterates over the response data, one line at a time.  When