提交 e0f1a7dc 编写于 作者: J Jay Pignata 提交者: Joshua Peek

If session_options[:id] is requested when using CookieStore, unmarshal the...

If session_options[:id] is requested when using CookieStore, unmarshal the session to access it [#2268 state:resolved]
Signed-off-by: NJoshua Peek <josh@joshpeek.com>
上级 f416f9f0
...@@ -37,7 +37,7 @@ module Session ...@@ -37,7 +37,7 @@ module Session
# "rake secret" and set the key in config/environment.rb. # "rake secret" and set the key in config/environment.rb.
# #
# Note that changing digest or secret invalidates all existing sessions! # Note that changing digest or secret invalidates all existing sessions!
class CookieStore class CookieStore < Hash
# Cookies can typically store 4096 bytes. # Cookies can typically store 4096 bytes.
MAX = 4096 MAX = 4096
SECRET_MIN_LENGTH = 30 # characters SECRET_MIN_LENGTH = 30 # characters
...@@ -50,6 +50,17 @@ class CookieStore ...@@ -50,6 +50,17 @@ class CookieStore
:httponly => true :httponly => true
}.freeze }.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_KEY = "rack.session".freeze
ENV_SESSION_OPTIONS_KEY = "rack.session.options".freeze ENV_SESSION_OPTIONS_KEY = "rack.session.options".freeze
HTTP_SET_COOKIE = "Set-Cookie".freeze HTTP_SET_COOKIE = "Set-Cookie".freeze
...@@ -90,7 +101,7 @@ def initialize(app, options = {}) ...@@ -90,7 +101,7 @@ def initialize(app, options = {})
def call(env) def call(env)
env[ENV_SESSION_KEY] = AbstractStore::SessionHash.new(self, 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) status, headers, body = @app.call(env)
......
...@@ -30,7 +30,7 @@ def get_session_value ...@@ -30,7 +30,7 @@ def get_session_value
end end
def get_session_id def get_session_id
render :text => "foo: #{session[:foo].inspect}; id: #{request.session_options[:id]}" render :text => "id: #{request.session_options[:id]}"
end end
def call_reset_session def call_reset_session
...@@ -119,7 +119,7 @@ def test_getting_session_id ...@@ -119,7 +119,7 @@ def test_getting_session_id
get '/get_session_id' get '/get_session_id'
assert_response :success assert_response :success
assert_equal "foo: \"bar\"; id: #{session_id}", response.body assert_equal "id: #{session_id}", response.body
end end
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册