Cookie Memoization

閲覧: 11 回
最初の未読メッセージにスキップ

Olly Legg

未読、
2009/05/06 12:35:092009/05/06
To: Ruby on Rails: Core
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.

cookies.rb: http://github.com/rails/rails/blob/7f1f16c01fd42701747daf9f3399dcdd300125f4/actionpack/lib/action_controller/cookies.rb#L72-82

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: http://gist.github.com/107595

Cheers, Olly

Olly

未読、
2009/05/28 8:50:282009/05/28
To: Ruby on Rails: Core
OK, I think this change makes sense so I wiped up a patch.

+1s, improvements and objections appreciated:
https://rails.lighthouseapp.com/projects/8994/tickets/2733-patch-memoize-cookies-so-they-can-be-retrieved-in-the-same-response-request-cycle

On May 6, 5:35 pm, Olly Legg <ollyl...@gmail.com> wrote:
> 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.
>
> cookies.rb:http://github.com/rails/rails/blob/7f1f16c01fd42701747daf9f3399dcdd30...
全員に返信
投稿者に返信
転送
新着メール 0 件