Skip to content
Myr

Use session cookies when following redirects

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

When a redirect was followed, only the cookies set by the initial response were used in the follow-up request. Fixes #1228.

authored by Miikka Koskinen · committed by Miikka Koskinen · parent e958511 · Browse files · 1 file+7 added−3 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−3 removed

  • other:+7 added−3 removed

1 file+7 added−3 removed

modified:requests/sessions.py+7 added-3 removed
78 unmodified lines
798081class SessionRedirectMixin(object):82 def resolve_redirects(self, resp, req, stream=False, timeout=None,83 verify=True, cert=None, proxies=None):83 verify=True, cert=None, proxies=None, cookies=None):84 """Receives a Response. Returns a generator of Responses."""8586 i = 087 prepared_request = PreparedRequest()
1 unmodified line
89 prepared_request.headers = req.headers.copy()90 prepared_request.hooks = req.hooks91 prepared_request.method = req.method92 prepared_request.url = req.url93 cookiejar = resp.cookies9394 cookiejar = cookiejar_from_dict({})95 cookiejar.update(cookies)96 cookiejar.update(resp.cookies)9798 # ((resp.status_code is codes.see_other))99 while (('location' in resp.headers and resp.status_code in REDIRECT_STATI)):100101 resp.content # Consume socket so it can be released
308 unmodified lines
410 verify = kwargs.get('verify')411 cert = kwargs.get('cert')412 proxies = kwargs.get('proxies')413 hooks = request.hooks414 cookies = self.cookies415416 # Get the appropriate adapter to use417 adapter = self.get_adapter(url=request.url)418
9 unmodified lines
428429 # Redirect resolving generator.430 gen = self.resolve_redirects(r, request, stream=stream,431 timeout=timeout, verify=verify, cert=cert,428 proxies=proxies)432 proxies=proxies, cookies=cookies)433434 # Resolve redirects if allowed.435 history = [resp for resp in gen] if allow_redirects else []436
41 unmodified lines