accept a hash as sessions setting

This commit is contained in:
Konstantin Haase 2011-03-19 10:25:00 +01:00
parent eb2871380c
commit 0c9e3d869e
4 changed files with 23 additions and 1 deletions

View File

@ -2,6 +2,8 @@
* Added support for HTTP PATCH requests. (Konstantin Haase)
* The sessions setting now may be an options hash. (Konstantin Haase)
* Important: 1.8.6 support has been dropped. (Konstantin Haase)
= 1.2.1 / 2011-03-17

View File

@ -810,6 +810,11 @@ set the secret yourself, so all your application instances share it:
set :session_secret, 'super secret'
If you want to configure it further, you may also store a hash with options in
the +sessions+ setting:
set :sessions, :domain => 'foo.com'
=== Halting
To immediately stop a request within a filter or route use:

View File

@ -1248,7 +1248,9 @@ module Sinatra
private
def setup_sessions(builder)
return unless sessions?
builder.use Rack::Session::Cookie, :secret => session_secret
options = { :secret => session_secret }
options.merge! sessions.to_hash if sessions.respond_to? :to_hash
builder.use Rack::Session::Cookie, options
end
def detect_rack_handler

View File

@ -284,6 +284,19 @@ class HelpersTest < Test::Unit::TestCase
get '/'
assert_body 'ok'
end
it 'accepts an options hash' do
mock_app do
set :sessions, :foo => :bar
get '/' do
assert_equal env['rack.session.options'][:foo], :bar
'ok'
end
end
get '/'
assert_body 'ok'
end
end
describe 'mime_type' do