Class: Rack::Session::HashedCookie

Inherits:
Cookie
  • Object
show all
Defined in:
lib/rack/session/hashed_cookie.rb

Overview

Port of Action Controller’s cookie-based session store (Copyright © 2004-2008 David Heinemeier Hansson).

Rack::Session::HashedCookie provides simple cookie based session management. The session is a Ruby Hash stored as base64 encoded marshalled data set to :key (default: rack.session).

Example:

use Rack::Session::Cookie, :key => 'rack.session',
                           :domain => 'foo.com',
                           :path => '/',
                           :expire_after => 2592000,
                           :digest => 'SHA256',
                           :secret => 'my long secret string'

All parameters but :secret are optional.

Constant Summary collapse

MAX =

Cookies can typically store 4096 bytes.

4096
SECRET_MIN_LENGTH =

characters

30

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ HashedCookie

Returns a new instance of HashedCookie.



28
29
30
31
32
33
# File 'lib/rack/session/hashed_cookie.rb', line 28

def initialize(app, options = {})
  @secret = options.delete(:secret)
  @digest = options.delete(:digest) || 'SHA1'
  super
  ensure_secret_secure(@secret)
end