Skip to content

Commit

Permalink
move Session::Pool to new superclass
Browse files Browse the repository at this point in the history
ID is deprecated, and we only want to deal with request objects, so move
to the new superclass.
  • Loading branch information
tenderlove committed Sep 5, 2015
1 parent 23a9fdf commit c000c63
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions lib/rack/request.rb
Expand Up @@ -133,6 +133,7 @@ def query_string; get_header(QUERY_STRING).to_s end
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
Expand Down
2 changes: 1 addition & 1 deletion lib/rack/session/abstract/id.rb
Expand Up @@ -394,7 +394,7 @@ def delete_session(req, sid, options)

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)
Expand Down
18 changes: 9 additions & 9 deletions lib/rack/session/pool.rb
Expand Up @@ -24,7 +24,7 @@ module Session
# )
# 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

Expand All @@ -41,8 +41,8 @@ def generate_sid
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
Expand All @@ -51,22 +51,22 @@ def get_session(env, sid)
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?
Expand Down

0 comments on commit c000c63

Please sign in to comment.