mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
Merge pull request #577 from slingamn/redirects_537
Fix and test for #537
This commit is contained in:
@@ -229,8 +229,10 @@ class Session(object):
|
||||
r.send(prefetch=prefetch)
|
||||
|
||||
# Send any cookies back up the to the session.
|
||||
for cookie in r.response.cookies:
|
||||
self.cookies.set_cookie(cookie)
|
||||
# (in safe mode, cookies may be None if the request didn't succeed)
|
||||
if r.response.cookies is not None:
|
||||
for cookie in r.response.cookies:
|
||||
self.cookies.set_cookie(cookie)
|
||||
|
||||
# Return the response.
|
||||
return r.response
|
||||
|
||||
@@ -847,5 +847,15 @@ class RequestsTestSuite(TestSetup, TestBaseMixin, unittest.TestCase):
|
||||
r = requests.get(httpbin('status', '404'))
|
||||
r.text
|
||||
|
||||
def test_max_redirects(self):
|
||||
def unsafe_callable():
|
||||
requests.get("http://httpbin.org/redirect/3", config=dict(max_redirects=2))
|
||||
self.assertRaises(requests.exceptions.TooManyRedirects, unsafe_callable)
|
||||
|
||||
# add safe mode
|
||||
response = requests.get("http://httpbin.org/redirect/3", config=dict(safe_mode=True, max_redirects=2))
|
||||
self.assertTrue(response.content is None)
|
||||
self.assertTrue(isinstance(response.error, requests.exceptions.TooManyRedirects))
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user