From d289eb22f164e0bc71c81b191c1f00bdd08fe669 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 4 Mar 2014 16:33:40 -0500 Subject: [PATCH] Always honor decode_unicode, even when _content is present. --HG-- extra : amend_source : 25977a1227b163d49bf2e1aec6aa448e5cd3be8a --- requests/models.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/requests/models.py b/requests/models.py index 682cd9e1..c55e6ea7 100644 --- a/requests/models.py +++ b/requests/models.py @@ -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