Cookie Memoization

Whilst trying to access cookie values that had been set in the current request in the view, I discovered that a new CookieJar is instantiated with every call to ActionController::Base#cookies.

Obviously in standard HTTP requests cookies can only be retrieved in subsequent requests to the one they were set in. However the code for CookieJar seems to suggest that the intention was to be able to access the cookies immediately after they had been set, as CookieJar is a sub-class of Hash.


Because a new CookieJar is instantiated with each access, any changes are discarded.

What do people think the intended behavior is? We could easily keep the changes to the cookie jar, by only instantiating one CookieJar per request. The following code in my ApplicationController, changes the behavior to the later:

Cheers, Olly

OK, I think this change makes sense so I wiped up a patch.

+1s, improvements and objections appreciated: