Sinatraã®Sessionã«ã¯æ³¨æ
Sinatraã§Sessionã¯ãããªé¢¨ã«ä½¿ãã¾ã
enable :sessions get '/foo' do session[:message] = 'Hello World!' redirect '/bar' end get '/bar' do session[:message] end
Sinatraã§ã¯Rackã®CookieSessionãã¤ãã£ã¦ãã®ã§ãããsecretãã¼ãæå®ãã¦ããªããããMarshalãã¦Base64ããã ãã®ãã¼ã¿ãã¯ããã¼ã«ä¹ãã¦ãã¾ãã
ãã®ã¾ã¾ããæ¸ãæãããã¦å¤§å¤ãªäºã«ãªãã®ã§ãããã©ã«ãã®sessionã¯æå¹ã«ããã«ãRackã®Sessionãsecretãã¼ãæå®ãã¦ä½¿ãã¹ãã§ã¯ãªãã ããããsecretãã¼ãæå®ããå ´åã¯ããã¼ã¿ã¨digestãã¯ããã¼ã«ä¹ãã¦ããã®ã§æ¸ãæããæ¤åºã§ãã¾ãã
use Rack::Session::Cookie, #:key => 'rack.session', #:domain => 'foo.com', #:path => '/', :expire_after => 3600, :secret => 'change' get '/foo' do session[:message] = 'Hello World!' redirect '/bar' end get '/bar' do session[:message] # => 'Hello World!' end
Sinatraã®ä½¿ãæ¹ã¯ã³ã³ã«æ¸ãã¾ãã
http://labs.unoh.net/2009/05/sinatra.html