Class: ActionController::Session::AbstractStore
- Defined in:
- lib/action_controller/session/abstract_store.rb
Defined Under Namespace
Classes: SessionHash
Constant Summary collapse
- ENV_SESSION_KEY =
'rack.session'.freeze
- ENV_SESSION_OPTIONS_KEY =
'rack.session.options'.freeze
- HTTP_COOKIE =
'HTTP_COOKIE'.freeze
- SET_COOKIE =
'Set-Cookie'.freeze
- DEFAULT_OPTIONS =
{ :key => '_session_id', :path => '/', :domain => nil, :expire_after => nil, :secure => false, :httponly => true, :cookie_only => true }
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ AbstractStore
constructor
A new instance of AbstractStore.
Constructor Details
#initialize(app, options = {}) ⇒ AbstractStore
Returns a new instance of AbstractStore.
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/action_controller/session/abstract_store.rb', line 97 def initialize(app, = {}) # Process legacy CGI options = .symbolize_keys if .has_key?(:session_path) ActiveSupport::Deprecation.warn "Giving :session_path to SessionStore is deprecated, " << "please use :path instead", caller [:path] = .delete(:session_path) end if .has_key?(:session_key) ActiveSupport::Deprecation.warn "Giving :session_key to SessionStore is deprecated, " << "please use :key instead", caller [:key] = .delete(:session_key) end if .has_key?(:session_http_only) ActiveSupport::Deprecation.warn "Giving :session_http_only to SessionStore is deprecated, " << "please use :httponly instead", caller [:httponly] = .delete(:session_http_only) end @app = app @default_options = DEFAULT_OPTIONS.merge() @key = @default_options[:key] @cookie_only = @default_options[:cookie_only] end |
Instance Method Details
#call(env) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/action_controller/session/abstract_store.rb', line 122 def call(env) session = SessionHash.new(self, env) env[ENV_SESSION_KEY] = session env[ENV_SESSION_OPTIONS_KEY] = @default_options.dup response = @app.call(env) session_data = env[ENV_SESSION_KEY] = env[ENV_SESSION_OPTIONS_KEY] if !session_data.is_a?(AbstractStore::SessionHash) || session_data.send(:loaded?) || [:expire_after] session_data.send(:load!) if session_data.is_a?(AbstractStore::SessionHash) && !session_data.send(:loaded?) sid = [:id] || generate_sid unless set_session(env, sid, session_data.to_hash) return response end = Rack::Utils.escape(@key) + '=' + Rack::Utils.escape(sid) << "; domain=#{[:domain]}" if [:domain] << "; path=#{[:path]}" if [:path] if [:expire_after] expiry = Time.now + [:expire_after] << "; expires=#{expiry.httpdate}" end << "; Secure" if [:secure] << "; HttpOnly" if [:httponly] headers = response[1] unless headers[SET_COOKIE].blank? headers[SET_COOKIE] << "\n#{}" else headers[SET_COOKIE] = end end response end |