Skip to content
Myr

fix #1287: Make sure expired cookies get removed from session.cookies

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

authored by Chase Sterling · committed by Chase Sterling · parent dccfc5b · Browse files · 1 file+7 added−11 removed
This commit

State

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

Diff stats

1 file+7 added−11 removed

  • other:+7 added−11 removed

1 file+7 added−11 removed

modified:requests/sessions.py+7 added-11 removed
10 unmodified lines
11import os12from datetime import datetime1314from .compat import cookielib15from .cookies import cookiejar_from_dict15from .cookies import cookiejar_from_dict, extract_cookies_to_jar16from .models import Request, PreparedRequest17from .hooks import default_hooks, dispatch_hook18from .utils import from_key_val_list, default_headers19from .exceptions import TooManyRedirects, InvalidSchema
70 unmodified lines
90 prepared_request.hooks = req.hooks91 prepared_request.method = req.method92 prepared_request.url = req.url9394 cookiejar = cookiejar_from_dict({})95 cookiejar.update(self.cookies)96 cookiejar.update(resp.cookies)9794 # ((resp.status_code is codes.see_other))95 while (('location' in resp.headers and resp.status_code in REDIRECT_STATI)):9697 resp.content # Consume socket so it can be released
44 unmodified lines
142 del headers['Cookie']143 except KeyError:144 pass145150 prepared_request.prepare_cookies(cookiejar)146 prepared_request.prepare_cookies(self.cookies)147148 resp = self.send(149 prepared_request,150 stream=stream,
3 unmodified lines
154 proxies=proxies,155 allow_redirects=False,156 )157162 cookiejar.update(resp.cookies)158 extract_cookies_to_jar(self.cookies, prepared_request, resp.raw)159160 i += 1161 yield resp162167 resp.cookies.update(cookiejar)163 resp.cookies = self.cookies.copy()164165166class Session(SessionRedirectMixin):167 """A Requests session.
176 unmodified lines
344 'allow_redirects': allow_redirects,345 }346 resp = self.send(prep, **send_kwargs)347352 # Persist cookies.353 self.cookies.update(resp.cookies)354348 return resp349350 def get(self, url, **kwargs):351 """Sends a GET request. Returns :class:`Response` object.
100 unmodified lines
452453 # Response manipulation hooks454 r = dispatch_hook('response', hooks, r, **kwargs)455456 # Persist cookies457 extract_cookies_to_jar(self.cookies, request, r.raw)458459 # Redirect resolving generator.460 gen = self.resolve_redirects(r, request, stream=stream,461 timeout=timeout, verify=verify, cert=cert,462 proxies=proxies)
45 unmodified lines