All cookies set during redirects are no longer stored on the Response object

Until version 1.2.0 a Response object would keep all cookies set during a redirection chain. This behavior was changed in version 1.2.1 (commit 1e465fd25554e4da84909fe1bd054c30c79ef05e).

cURL and, I believe, all major used browsers ( http://blog.dubbelboer.com/2012/11/25/302-cookie.html ) will keep cookies set during redirections for futher requests. This is not the current behavior for python-requests.

I propose to revert 1e465fd25554e4da84909fe1bd054c30c79ef05e to keep python-requests in consistency with other implementations.

This was an issue that I found when dealing with Google Client Login and Google App Engine authentication. Current version forces me to look at each request from request.history to retrieve each cookie set during redirects. The default behavior should be the opposite, since there are few cases where someone would not keep cookies defined from previous redirects.


Hi @matheusgr, thanks for opening this issue!

To be clear, are you experiencing that we're not sending cookies that we should be sending, or are you simply frustrated about being unable to easily see the full set of cookies? If it's the second, have you tried looking at `Session.cookies`?


The second case. I now need to look at each response at response.history to see all cookies set at redirects.

I also tried to use a Session object, but it also only stores the last cookie recieved during redirects.


@matheusgr That shouldn't be true unless the remote server is unsetting them. If the remote server _is_ unsetting them then the previous behaviour was actually a bug. Are you finding that we're definitely losing the other cookies?


I put an webapp that sets three cookies -- one at each redirect (/r1, /r2) and one on the final location (/r3).

I can have access those cookies if I look at the response/session history. But those cookies are not accessible from the response/session cookies attribute. I can confirm that the server is not unsetting them.

V1.2.0:

```
>>> [cookie.name for cookie in requests.get('http://requestredirect.appspot.com/r1').cookies]
['r1', 'r2', 'r3']
```

V1.2.3:

```
>>> [cookie.name for cookie in requests.get('http://requestredirect.appspot.com/r1').cookies]
['r3']
>>> [[c.name for c in r.cookies] for r in requests.get('http://requestredirect.appspot.com/r1').history]
[['r1'], ['r2']]

>>> s = requests.Session()
>>> [cookie.name for cookie in s.get('http://requestredirect.appspot.com/r1').cookies]
['r3']
>>> [[c.name for c in r.cookies] for r in s.get('http://requestredirect.appspot.com/r1').history]
[['r1'], ['r2']]
```


Oh, that's a problem. Give me a little while, I'll see if I can easily reproduce it.


I'm sorry, I should have read your code more carefuly. Your v1.2.3 session code is incorrect. You should be doing:

``` python
>>> s = requests.Session()
>>> s.get('http://requestredirect.appspot.com/r1')
>>> [cookie.name for cookie in s.cookies]
['r1', 'r2', 'r3']
```


Oh, ok, my mistake... the `s.get()` will only return the last response
cookies, not the full session cookies. I will close this issue. Thank you
for all your answers!

On Sat, Jun 8, 2013 at 3:12 PM, Cory Benfield notifications@github.comwrote:

> I'm sorry, I should have read your code more carefuly. Your v1.2.3 session
> code is incorrect. You should be doing:
> 
> > > > s = requests.Session()>>> s.get('http://requestredirect.appspot.com/r1')>>> [cookie.name for cookie in s.cookies]['r1', 'r2', 'r3']
> 
> —
> Reply to this email directly or view it on GitHubhttps://github.com/kennethreitz/requests/issues/1410#issuecomment-19152915
> .

## 

http://sites.google.com/site/matheusgr/
matheusgr@gmail.com


`s.get()` returns the final `Response` object, and then the `.cookies` acts on that. =)

It's not a problem, please let me know if you have any more problems! Glad I could help. :cake: