diff options
author | Jay Pignata <john.pignata@gmail.com> | 2009-09-03 11:50:01 -0500 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2009-09-03 11:50:01 -0500 |
commit | e0f1a7dc191ffebc9f6cadb6232e567fee8aa491 (patch) | |
tree | ec7894f3366b5b9671f1082a5d8643eb7111aba8 /actionpack | |
parent | f416f9f0aef654fea94cae10027aca866d07c659 (diff) | |
download | rails-e0f1a7dc191ffebc9f6cadb6232e567fee8aa491.tar.gz rails-e0f1a7dc191ffebc9f6cadb6232e567fee8aa491.tar.bz2 rails-e0f1a7dc191ffebc9f6cadb6232e567fee8aa491.zip |
If session_options[:id] is requested when using CookieStore, unmarshal the session to access it [#2268 state:resolved]
Signed-off-by: Joshua Peek <josh@joshpeek.com>
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_dispatch/middleware/session/cookie_store.rb | 17 | ||||
-rw-r--r-- | actionpack/test/dispatch/session/cookie_store_test.rb | 4 |
2 files changed, 16 insertions, 5 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb b/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb index 9cfd6956d0..0e477ba9ae 100644 --- a/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb +++ b/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb @@ -37,7 +37,7 @@ module ActionDispatch # "rake secret" and set the key in config/environment.rb. # # Note that changing digest or secret invalidates all existing sessions! - class CookieStore + class CookieStore < Hash # Cookies can typically store 4096 bytes. MAX = 4096 SECRET_MIN_LENGTH = 30 # characters @@ -49,7 +49,18 @@ module ActionDispatch :expire_after => nil, :httponly => true }.freeze + + class OptionsHash < Hash + def initialize(by, env, default_options) + @session_data = env[CookieStore::ENV_SESSION_KEY] + default_options.each { |key, value| self[key] = value } + end + def [](key) + key == :id ? @session_data[:session_id] : super(key) + end + end + ENV_SESSION_KEY = "rack.session".freeze ENV_SESSION_OPTIONS_KEY = "rack.session.options".freeze HTTP_SET_COOKIE = "Set-Cookie".freeze @@ -90,8 +101,8 @@ module ActionDispatch def call(env) env[ENV_SESSION_KEY] = AbstractStore::SessionHash.new(self, env) - env[ENV_SESSION_OPTIONS_KEY] = @default_options.dup - + env[ENV_SESSION_OPTIONS_KEY] = OptionsHash.new(self, env, @default_options) + status, headers, body = @app.call(env) session_data = env[ENV_SESSION_KEY] diff --git a/actionpack/test/dispatch/session/cookie_store_test.rb b/actionpack/test/dispatch/session/cookie_store_test.rb index 0723a76d2b..d695be0be4 100644 --- a/actionpack/test/dispatch/session/cookie_store_test.rb +++ b/actionpack/test/dispatch/session/cookie_store_test.rb @@ -30,7 +30,7 @@ class CookieStoreTest < ActionController::IntegrationTest end def get_session_id - render :text => "foo: #{session[:foo].inspect}; id: #{request.session_options[:id]}" + render :text => "id: #{request.session_options[:id]}" end def call_reset_session @@ -119,7 +119,7 @@ class CookieStoreTest < ActionController::IntegrationTest get '/get_session_id' assert_response :success - assert_equal "foo: \"bar\"; id: #{session_id}", response.body + assert_equal "id: #{session_id}", response.body end end |