From: Chase Sterling Date: Fri, 5 Apr 2013 02:11:38 +0000 (-0400) Subject: fix #1287: Make sure expired cookies get removed from session.cookies X-Git-Tag: v1.2.1~24^2~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d22ac00098475367ea0c0725d7db94d7967b09b1;p=services%2Fpython-requests.git fix #1287: Make sure expired cookies get removed from session.cookies --- diff --git a/requests/sessions.py b/requests/sessions.py index ff40a6c..f37d009 100644 --- a/requests/sessions.py +++ b/requests/sessions.py @@ -12,7 +12,7 @@ import os from datetime import datetime from .compat import cookielib -from .cookies import cookiejar_from_dict +from .cookies import cookiejar_from_dict, extract_cookies_to_jar from .models import Request, PreparedRequest from .hooks import default_hooks, dispatch_hook from .utils import from_key_val_list, default_headers @@ -91,10 +91,6 @@ class SessionRedirectMixin(object): prepared_request.method = req.method prepared_request.url = req.url - 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)): @@ -147,7 +143,7 @@ class SessionRedirectMixin(object): except KeyError: pass - prepared_request.prepare_cookies(cookiejar) + prepared_request.prepare_cookies(self.cookies) resp = self.send( prepared_request, @@ -159,12 +155,12 @@ class SessionRedirectMixin(object): allow_redirects=False, ) - cookiejar.update(resp.cookies) + extract_cookies_to_jar(self.cookies, prepared_request, resp.raw) i += 1 yield resp - resp.cookies.update(cookiejar) + resp.cookies = self.cookies.copy() class Session(SessionRedirectMixin): @@ -349,9 +345,6 @@ class Session(SessionRedirectMixin): } resp = self.send(prep, **send_kwargs) - # Persist cookies. - self.cookies.update(resp.cookies) - return resp def get(self, url, **kwargs): @@ -460,6 +453,9 @@ class Session(SessionRedirectMixin): # Response manipulation hooks r = dispatch_hook('response', hooks, r, **kwargs) + # Persist cookies + extract_cookies_to_jar(self.cookies, request, r.raw) + # Redirect resolving generator. gen = self.resolve_redirects(r, request, stream=stream, timeout=timeout, verify=verify, cert=cert,