aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/middleware/session
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/lib/action_dispatch/middleware/session')
-rw-r--r--actionpack/lib/action_dispatch/middleware/session/abstract_store.rb41
-rw-r--r--actionpack/lib/action_dispatch/middleware/session/cookie_store.rb7
2 files changed, 40 insertions, 8 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
index 6c039cf62d..6d109f4624 100644
--- a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
+++ b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
@@ -15,6 +15,7 @@ module ActionDispatch
@by = by
@env = env
@loaded = false
+ @updated = false
end
def session_id
@@ -26,12 +27,13 @@ module ActionDispatch
def [](key)
load! unless @loaded
- super
+ super(key.to_s)
end
def []=(key, value)
load! unless @loaded
- super
+ super(key.to_s, value)
+ @updated = true
end
def to_hash
@@ -40,6 +42,24 @@ module ActionDispatch
h
end
+ def update(hash = nil)
+ if hash.nil?
+ ActiveSupport::Deprecation.warn('use replace instead', caller)
+ replace({})
+ else
+ super(hash.stringify_keys)
+ end
+ end
+
+ def delete(key = nil)
+ if key.nil?
+ ActiveSupport::Deprecation.warn('use clear instead', caller)
+ clear
+ else
+ super(key.to_s)
+ end
+ end
+
def data
ActiveSupport::Deprecation.warn(
"ActionController::Session::AbstractStore::SessionHash#data " +
@@ -47,6 +67,10 @@ module ActionDispatch
to_hash
end
+ def close
+ ActiveSupport::Deprecation.warn('sessions should no longer be closed', caller)
+ end
+
def inspect
load! unless @loaded
super
@@ -57,11 +81,15 @@ module ActionDispatch
@loaded
end
+ def updated?
+ @updated
+ end
+
def load!
stale_session_check! do
id, session = @by.send(:load_session, @env)
(@env[ENV_SESSION_OPTIONS_KEY] ||= {})[:id] = id
- replace(session)
+ replace(session.stringify_keys)
@loaded = true
end
end
@@ -74,7 +102,7 @@ module ActionDispatch
# Note that the regexp does not allow $1 to end with a ':'
$1.constantize
rescue LoadError, NameError => const_error
- raise ActionController::SessionRestoreError, "Session contains objects whose class definition isn\\'t available.\nRemember to require the classes for all objects kept in the session.\n(Original exception: \#{const_error.message} [\#{const_error.class}])\n"
+ raise ActionController::SessionRestoreError, "Session contains objects whose class definition isn't available.\nRemember to require the classes for all objects kept in the session.\n(Original exception: #{const_error.message} [#{const_error.class}])\n"
end
retry
@@ -125,7 +153,10 @@ module ActionDispatch
options = env[ENV_SESSION_OPTIONS_KEY]
if !session_data.is_a?(AbstractStore::SessionHash) || session_data.send(:loaded?) || options[:expire_after]
- session_data.send(:load!) if session_data.is_a?(AbstractStore::SessionHash) && !session_data.send(:loaded?)
+ if session_data.is_a?(AbstractStore::SessionHash)
+ session_data.send(:load!) if !session_data.send(:loaded?)
+ return response if !session_data.send(:updated?)
+ end
sid = options[:id] || generate_sid
diff --git a/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb b/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb
index 433c4cc070..547a2d2062 100644
--- a/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb
+++ b/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb
@@ -143,7 +143,8 @@ module ActionDispatch
request = Rack::Request.new(env)
session_data = request.cookies[@key]
data = unmarshal(session_data) || persistent_session_id!({})
- [data[:session_id], data]
+ data.stringify_keys!
+ [data["session_id"], data]
end
# Marshal a session hash into safe cookie data. Include an integrity hash.
@@ -206,12 +207,12 @@ module ActionDispatch
end
def inject_persistent_session_id(data)
- requires_session_id?(data) ? { :session_id => generate_sid } : {}
+ requires_session_id?(data) ? { "session_id" => generate_sid } : {}
end
def requires_session_id?(data)
if data
- data.respond_to?(:key?) && !data.key?(:session_id)
+ data.respond_to?(:key?) && !data.key?("session_id")
else
true
end