lib/global_session/rack.rb in global_session-2.0.1 vs lib/global_session/rack.rb in global_session-2.0.2
- old
+ new
@@ -86,41 +86,50 @@
# the environment and passes it up the chain.
def call(env)
env['rack.cookies'] = {} unless env['rack.cookies']
begin
+ err = nil
read_cookie(env)
- rescue Exception => e
- env['global_session'] = @directory.create_session
- handle_error('reading session cookie', env, e)
+ rescue Exception => read_err
+ err = read_err
+
+ # Catch "double whammy" errors
+ begin
+ env['global_session'] = @directory.create_session
+ rescue Exception => create_err
+ err = create_err
+ end
+
+ handle_error('reading session cookie', env, err)
end
tuple = nil
begin
tuple = @app.call(env)
- rescue Exception => e
- handle_error('processing request', env, e)
+ rescue Exception => read_err
+ handle_error('processing request', env, read_err)
return tuple
else
renew_cookie(env)
update_cookie(env)
return tuple
end
end
protected
-
+
# Read a cookie from the Rack environment.
#
# === Parameters
# env(Hash): Rack environment.
def read_cookie(env)
- if env['rack.cookies'].has_key?(@cookie_name)
- env['global_session'] = @directory.create_session(env['rack.cookies'][@cookie_name])
- elsif @cookie_retrieval && cookie = @cookie_retrieval.call(env)
- env['global_session'] = @directory.create_session(cookie)
+ if @cookie_retrieval && (cookie = @cookie_retrieval.call(env))
+ env['global_session'] = @directory.load_session(cookie)
+ elsif env['rack.cookies'].has_key?(@cookie_name)
+ env['global_session'] = @directory.load_session(env['rack.cookies'][@cookie_name])
else
env['global_session'] = @directory.create_session
end
true
@@ -129,11 +138,11 @@
# Renew the session ticket.
#
# === Parameters
# env(Hash): Rack environment
def renew_cookie(env)
- return unless env['global_session'].directory.local_authority_name
+ return unless @directory.local_authority_name
return if env['global_session.req.renew'] == false
if (renew = @configuration['renew']) && env['global_session'] &&
env['global_session'].expired_at < Time.at(Time.now.utc + 60 * renew.to_i)
env['global_session'].renew!
@@ -143,11 +152,11 @@
# Update the cookie jar with the revised ticket.
#
# === Parameters
# env(Hash): Rack environment
def update_cookie(env)
- return unless env['global_session'].directory.local_authority_name
+ return unless @directory.local_authority_name
return if env['global_session.req.update'] == false
domain = @configuration['cookie']['domain'] || env['SERVER_NAME']
session = env['global_session']
@@ -177,10 +186,10 @@
# Delete the global session cookie from the cookie jar.
#
# === Parameters
# env(Hash): Rack environment
def wipe_cookie(env)
- return unless env['global_session'].directory.local_authority_name
+ return unless @directory.local_authority_name
return if env['global_session.req.update'] == false
domain = @configuration['cookie']['domain'] || env['SERVER_NAME']
env['rack.cookies'][@cookie_name] = {:value => nil, :domain => domain, :expires => Time.at(0)}
end