Added test case to handle response of streamed redirects.
authorschlamar <marc.schlaich@gmail.com>
Thu, 13 Mar 2014 17:27:12 +0000 (18:27 +0100)
committerschlamar <marc.schlaich@gmail.com>
Mon, 12 May 2014 20:45:45 +0000 (22:45 +0200)
Credits go to @zackw.

test_requests.py

index a1df1f19090bc812b94c735c53ee0ad774ecc38f..e3eacd6f623183805b069df2703c1c116e85c1f8 100755 (executable)
@@ -917,6 +917,25 @@ class RequestsTestCase(unittest.TestCase):
 
         assert h1 == h2
 
+    def test_manual_redirect_with_partial_body_read(self):
+        s = requests.Session()
+        r1 = s.get(httpbin('redirect/2'), allow_redirects=False, stream=True)
+        assert r1.is_redirect
+        rg = s.resolve_redirects(r1, r1.request, stream=True)
+
+        # read only the first eight bytes of the response body,
+        # then follow the redirect
+        r1.iter_content(8)
+        r2 = next(rg)
+        assert r2.is_redirect
+
+        # read all of the response via iter_content,
+        # then follow the redirect
+        for _ in r2.iter_content():
+            pass
+        r3 = next(rg)
+        assert not r3.is_redirect
+
 
 class TestContentEncodingDetection(unittest.TestCase):
 
@@ -1321,7 +1340,7 @@ def test_data_argument_accepts_tuples(list_of_tuples):
             hooks=default_hooks()
         )
         assert p.body == urlencode(data)
-        
+
 
 if __name__ == '__main__':
     unittest.main()