diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2015-09-05 11:19:00 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2015-09-05 11:19:00 -0700 |
commit | c000c63283e937df6bf82af1aebd4ec77f6ad34d (patch) | |
tree | 71fdc4b690359970bfb565fa7784eb5397408568 | |
parent | 23a9fdfdd741a29f22a7e353d7fe6e39166b0ad6 (diff) | |
download | rack-c000c63283e937df6bf82af1aebd4ec77f6ad34d.tar.gz |
move Session::Pool to new superclass
ID is deprecated, and we only want to deal with request objects, so move to the new superclass.
-rw-r--r-- | lib/rack/request.rb | 1 | ||||
-rw-r--r-- | lib/rack/session/abstract/id.rb | 2 | ||||
-rw-r--r-- | lib/rack/session/pool.rb | 18 |
3 files changed, 11 insertions, 10 deletions
diff --git a/lib/rack/request.rb b/lib/rack/request.rb index afa5d590..0f9d1dbf 100644 --- a/lib/rack/request.rb +++ b/lib/rack/request.rb @@ -133,6 +133,7 @@ module Rack def content_length; get_header('CONTENT_LENGTH') end def logger; get_header(RACK_LOGGER) end def user_agent; get_header('HTTP_USER_AGENT') end + def multithread?; get_header(RACK_MULTITHREAD) end # the referer of the client def referer; get_header('HTTP_REFERER') end diff --git a/lib/rack/session/abstract/id.rb b/lib/rack/session/abstract/id.rb index 4a9edadf..5e568a6a 100644 --- a/lib/rack/session/abstract/id.rb +++ b/lib/rack/session/abstract/id.rb @@ -394,7 +394,7 @@ module Rack class ID < Persisted def self.inherited(klass) - k = klass.ancestors.find { |k| k.superclass == ID } + k = klass.ancestors.find { |kl| kl.superclass == ID } unless k.instance_variable_defined?(:"@_rack_warned") warn "#{klass} is inheriting from #{ID}. Inheriting from #{ID} is deprecated, please inherit from #{Persisted} instead" if $VERBOSE k.instance_variable_set(:"@_rack_warned", true) diff --git a/lib/rack/session/pool.rb b/lib/rack/session/pool.rb index 5953ced3..4c9c25c7 100644 --- a/lib/rack/session/pool.rb +++ b/lib/rack/session/pool.rb @@ -24,7 +24,7 @@ module Rack # ) # Rack::Handler::WEBrick.run sessioned - class Pool < Abstract::ID + class Pool < Abstract::Persisted attr_reader :mutex, :pool DEFAULT_OPTIONS = Abstract::ID::DEFAULT_OPTIONS.merge :drop => false @@ -41,8 +41,8 @@ module Rack end end - def get_session(env, sid) - with_lock(env) do + def find_session(req, sid) + with_lock(req) do unless sid and session = @pool[sid] sid, session = generate_sid, {} @pool.store sid, session @@ -51,22 +51,22 @@ module Rack end end - def set_session(env, session_id, new_session, options) - with_lock(env) do + def write_session(req, session_id, new_session, options) + with_lock(req) do @pool.store session_id, new_session session_id end end - def destroy_session(env, session_id, options) - with_lock(env) do + def delete_session(req, session_id, options) + with_lock(req) do @pool.delete(session_id) generate_sid unless options[:drop] end end - def with_lock(env) - @mutex.lock if env[RACK_MULTITHREAD] + def with_lock(req) + @mutex.lock if req.multithread? yield ensure @mutex.unlock if @mutex.locked? |