Merge pull request #1239 from miikka/fix-issue-1228

Use session cookies when following redirects
This commit is contained in:
Kenneth Reitz
2013-03-20 03:37:25 -07:00
2 changed files with 10 additions and 1 deletions
+4 -1
View File
@@ -90,7 +90,10 @@ class SessionRedirectMixin(object):
prepared_request.hooks = req.hooks
prepared_request.method = req.method
prepared_request.url = req.url
cookiejar = resp.cookies
cookiejar = cookiejar_from_dict({})
cookiejar.update(self.cookies)
cookiejar.update(resp.cookies)
# ((resp.status_code is codes.see_other))
while (('location' in resp.headers and resp.status_code in REDIRECT_STATI)):
+6
View File
@@ -118,6 +118,12 @@ class RequestsTestCase(unittest.TestCase):
r = s.get(url)
self.assertTrue(s.cookies['foo'] == 'bar')
def test_cookie_sent_on_redirect(self):
s = requests.session()
s.get(httpbin('cookies/set?foo=bar'))
r = s.get(httpbin('redirect/1')) # redirects to httpbin('get')
self.assertTrue("Cookie" in r.json()["headers"])
def test_user_agent_transfers(self):
heads = {