From 358478eb8881e3ebdef6afae09ee8ba934f66ee9 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Wed, 9 Nov 2011 14:57:38 -0800 Subject: [PATCH] Cookie persistence! --- requests/sessions.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/requests/sessions.py b/requests/sessions.py index 9a68e61..77a26e5 100644 --- a/requests/sessions.py +++ b/requests/sessions.py @@ -87,6 +87,9 @@ class Session(object): # Set up a CookieJar to be used by default self.cookies = {} + if cookies is not None: + self.cookies.update(cookies) + def __repr__(self): return '' % (id(self)) @@ -165,6 +168,7 @@ class Session(object): # Arguments manipulation hook. args = dispatch_hook('args', args['hooks'], args) + # Create the (empty) response. r = Request(**args) # Don't send if asked nicely. @@ -174,6 +178,10 @@ class Session(object): # Send the HTTP Request. r.send() + # Send any cookies back up the to the session. + self.cookies.update(r.response.cookies) + + # Return the response. return r.response -- 2.7.4