mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
Merge pull request #2168 from ContinuousFunction/master
Tracking Previous Requests
This commit is contained in:
@@ -91,10 +91,17 @@ class SessionRedirectMixin(object):
|
||||
"""Receives a Response. Returns a generator of Responses."""
|
||||
|
||||
i = 0
|
||||
hist = [] #keep track of history
|
||||
|
||||
while resp.is_redirect:
|
||||
prepared_request = req.copy()
|
||||
|
||||
if i > 0:
|
||||
#update history and keep track of redirects
|
||||
hist.append(resp)
|
||||
new_hist = list(hist)
|
||||
resp.history = new_hist
|
||||
|
||||
try:
|
||||
resp.content # Consume socket so it can be released
|
||||
except (ChunkedEncodingError, ContentDecodingError, RuntimeError):
|
||||
|
||||
@@ -974,6 +974,14 @@ class RequestsTestCase(unittest.TestCase):
|
||||
assert isinstance(s, builtin_str)
|
||||
assert s == "Basic dGVzdDp0ZXN0"
|
||||
|
||||
def test_requests_history_is_saved(self):
|
||||
r = requests.get('https://httpbin.org/redirect/5')
|
||||
total = r.history[-1].history
|
||||
i = 0
|
||||
for item in r.history:
|
||||
assert item.history == total[0:i]
|
||||
i=i+1
|
||||
|
||||
|
||||
class TestContentEncodingDetection(unittest.TestCase):
|
||||
|
||||
@@ -1364,6 +1372,7 @@ class TestRedirects:
|
||||
assert session.calls[-1] == send_call
|
||||
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def list_of_tuples():
|
||||
return [
|
||||
|
||||
Reference in New Issue
Block a user