Skip to content
Myr

Merge pull request #595 from reclosedev/sess-cookies-no-resp

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Session cookies not saved when Session.request is called with return_response=False

authored by Kenneth Reitz · committed by Kenneth Reitz · parents 0308a28, c010f58 · Browse files · 5 files+27 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+27 added−6 removed

  • tests:+20 added−0 removed
  • other:+7 added−6 removed

5 files+27 added−6 removed

modified:requests/models.py+6 added
201 unmodified lines
202203 # Save cookies in Response.204 response.cookies = self.cookies205206 # Save cookies in Session.207 # (in safe mode, cookies may be None if the request didn't succeed)208 if self.cookies is not None:209 for cookie in self.cookies:210 self.session.cookies.set_cookie(cookie)211212 # No exceptions were harmed in the making of this request.213 response.error = getattr(resp, 'error', None)214215 # Save original response for later.
637 unmodified lines
modified:requests/sessions.py-6 removed
226 unmodified lines
227228 # Send the HTTP Request.229 r.send(prefetch=prefetch)230231 # Send any cookies back up the to the session.232 # (in safe mode, cookies may be None if the request didn't succeed)233 if r.response.cookies is not None:234 for cookie in r.response.cookies:235 self.cookies.set_cookie(cookie)236231 # Return the response.232 return r.response233234
89 unmodified lines
modified:tests/test_requests_async.py+10 added
10 unmodified lines
11import select12has_poll = hasattr(select, "poll")1314from requests import async15import requests1617sys.path.append('.')18from test_requests import httpbin, RequestsTestSuite, SERVICES19
43 unmodified lines
63 def test_select_poll(self):64 """Test to make sure we don't overwrite the poll"""65 self.assertEqual(hasattr(select, "poll"), has_poll)6667 def test_async_with_session_cookies(self):68 s = requests.Session(cookies={'initial': '42'})69 r1 = get(httpbin('cookies/set/async/yes'), session=s)70 r2 = get(httpbin('cookies/set/no_session/yes'))71 assert 'initial' in r1.cookies72 assert 'initial' not in r2.cookies and 'async' not in r2.cookies73 assert 'async' in s.cookies74 assert 'no_session' not in s.cookies7576if __name__ == '__main__':77 unittest.main()
modified:tests/test_requests.py+10 added
724 unmodified lines
725 assert not params['a'] in r3.text726 assert params3['b'] in r3.text727 assert params3['c'] in r3.text728729 def test_session_cookies_with_return_response_false(self):730 s = requests.session()731 # return_response=False as it does requests.async.get732 rq = get(httpbin('cookies', 'set', 'k', 'v'), return_response=False,733 allow_redirects=True, session=s)734 rq.send(prefetch=True)735 c = rq.response.json.get('cookies')736 assert 'k' in c737 assert 'k' in s.cookies738739 def test_session_pickling(self):740741 s = requests.session(742 headers={'header': 'value'},
175 unmodified lines
modified:AUTHORS.rst+1 added
97 unmodified lines
98- Shivaram Lingamneni99- Miguel Turner100- Rohan Jain (crodjer)101- Justin Barber <barber.justin@gmail.com>102- Roman Haritonov <@reclosedev>