raise RuntimeError when a single streamed request calls *iter methods than once
authorTim Konick <konick781@gmail.com>
Mon, 22 Sep 2014 16:04:29 +0000 (12:04 -0400)
committerTim Konick <konick781@gmail.com>
Mon, 22 Sep 2014 16:04:29 +0000 (12:04 -0400)
requests/models.py

index bbf08c81358cfdd208c1301cbc209855355da178..a6af6427600ef98674e8c2cb7db51f8d29ccfc07 100644 (file)
@@ -655,8 +655,12 @@ class Response(object):
 
             self._content_consumed = True
 
-        # simulate reading small chunks of the content
-        reused_chunks = iter_slices(self._content, chunk_size)
+        if self._content_consumed and isinstance(self._content, bool):
+            raise RuntimeError(
+                        'The content for this response was already consumed')
+        else:
+            # simulate reading small chunks of the content
+            reused_chunks = iter_slices(self._content, chunk_size)
 
         stream_chunks = generate()