From d0a23c4920794c9f8dd4189d7432a6b49da898d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Tue, 17 Jan 2012 17:18:41 +0100 Subject: App: remove session_ prefix from session_options keys --- example/sample.ru | 4 ++-- lib/zorglub/app.rb | 8 ++++---- lib/zorglub/session.rb | 12 ++++++------ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/example/sample.ru b/example/sample.ru index a31aa8a..9dc4d13 100644 --- a/example/sample.ru +++ b/example/sample.ru @@ -65,7 +65,7 @@ APP = Zorglub::App.new do opt! :debug, true opt! :engine, :haml opt!:root, File.dirname( File.absolute_path(__FILE__) ) - opt(:session_options)[:session_on] = true + opt(:session_options)[:enabled] = true map '/url1', Node1 end # @@ -149,7 +149,7 @@ map '/' do use Rack::Lint use Rack::ShowExceptions if USE_RACK_SESSION - use Rack::Session::Cookie, :key=>Zorglub::Config.session_key, :secret=>Zorglub::Config.session_secret, + use Rack::Session::Cookie, :key=>APP.opt(:session_options)[:key], :secret=>APP.opt(:session_options)[:secret], :path=>'/', :http_only=>true, :expire_after=>30 end run APP diff --git a/lib/zorglub/app.rb b/lib/zorglub/app.rb index 2be2f6b..553dd3f 100644 --- a/lib/zorglub/app.rb +++ b/lib/zorglub/app.rb @@ -26,10 +26,10 @@ module Zorglub :encoding => 'utf-8' }, :session_options => { - :session_on => false, - :session_key => 'zorglub.sid', - :session_secret => 'session-secret-secret', - :session_sid_len => 64, + :enabled => false, + :key => 'zorglub.sid', + :secret => 'session-secret-secret', + :sid_len => 64, } } instance_eval &block if block_given? diff --git a/lib/zorglub/session.rb b/lib/zorglub/session.rb index 7e91555..7351a48 100644 --- a/lib/zorglub/session.rb +++ b/lib/zorglub/session.rb @@ -47,7 +47,7 @@ module Zorglub # def clear load_data! -# @response.delete_cookie @options[:session_key] +# @response.delete_cookie @options[:key] # @sessions.delete @sid # @sid = nil super @@ -95,11 +95,11 @@ module Zorglub # def load_data! return if loaded? - if @options[:session_on] - sid = @request.cookies[@options[:session_key]] + if @options[:enabled] + sid = @request.cookies[@options[:key]] if sid.nil? sid = generate_sid! - @response.set_cookie @options[:session_key], sid + @response.set_cookie @options[:key], sid end replace @sessions[sid] ||={} @sessions[sid] = self @@ -126,7 +126,7 @@ module Zorglub # SecureRandom is available since Ruby 1.8.7. # For Ruby versions earlier than that, you can require the uuidtools gem, # which has a drop-in replacement for SecureRandom. - def sid_algorithm; SecureRandom.hex(@options[:session_sid_len]); end + def sid_algorithm; SecureRandom.hex(@options[:sid_len]); end rescue LoadError require 'openssl' # Using OpenSSL::Random for generation, this is comparable in performance @@ -134,7 +134,7 @@ module Zorglub # have the same behaviour as the SecureRandom::hex method of the # uuidtools gem. def sid_algorithm - OpenSSL::Random.random_bytes(@options[:session_sid_len] / 2).unpack('H*')[0] + OpenSSL::Random.random_bytes(@options[:sid_len] / 2).unpack('H*')[0] end rescue LoadError # Digest::SHA2::hexdigest produces a string of length 64, although -- cgit v1.1-2-g2b99