abstract class
Session::Store(T)
- Session::Store(T)
- Reference
- Object
Overview
Abstract base class for session storage backends
Generic Constraint: T must inherit from Session::Base T must provide a parameterless constructor (T.new)
Example usage:
class UserSession < Session::Base
property? authenticated : Bool = false
property user_id : Int64? = nil
end
# Use memory store for development
store = Session::MemoryStore(UserSession).new
# Use Redis for production
store = Session::RedisStore(UserSession).new(Redis.new)
Direct Known Subclasses
- Session::ClusteredRedisStore(T)
- Session::CookieStore(T)
- Session::MemoryStore(T)
- Session::RedisStore(T)
Defined in:
store.crInstance Method Summary
-
#[](key : String) : T
Core store operations
- #[]=(key : String, session : T) : T
- #[]?(key : String) : T | Nil
-
#authenticate(& : T -> _) : T
Change the session's privileges (log in, switch user, elevate) and give it a new id in one step.
-
#build_cookie(name : String, value : String, host : String = "") : HTTP::Cookie
A cookie carrying the configured security attributes, expiring with the session timeout.
- #clear
- #create : T
- #create_session_cookie(host : String) : HTTP::Cookie
-
#current_session : T
The session of the request being served.
- #current_session=(current_session : T)
-
#current_session? : T | Nil
The current fiber's session, or nil when no request is being served on it.
- #delete(key : String)
-
#delete
Delete current session and create a new one
-
#encrypts_with_secret? : Bool
Whether this store encrypts sessions with
Session.config.secret. -
#flash : Flash
The current request's flash messages (those of its session).
- #load_from(request_cookies : HTTP::Cookies) : T | Nil
- #on(event : Symbol, session_id : String, session : T)
-
#regenerate_id : T
Regenerate session ID while preserving session data Important for security after authentication state changes
-
#release : Nil
Forget the current fiber's session once its request is done.
- #session_id : String
- #session_key
- #set_cookies(response_cookies : HTTP::Cookies, host : String = "") : Nil
- #size : Int64
-
#storage : String
Storage abstraction - must be implemented by subclasses
- #timeout
- #valid? : Bool
Instance Method Detail
Change the session's privileges (log in, switch user, elevate) and give it a new id in one step. Re-using the id a visitor had before logging in lets anyone who planted or observed it (session fixation) share the authenticated session.
store.authenticate { |session| session.user_id = user.id }
A cookie carrying the configured security attributes, expiring with the session timeout.
The session of the request being served. A store is shared by every request, so it is
kept per fiber: concurrent requests, and the next request on a keep-alive connection,
never see each other's session. SessionHandler calls #release when a request ends.
A fiber spawned during a request starts with a blank session; capture the session
before spawn to use it there.
The current fiber's session, or nil when no request is being served on it.
Whether this store encrypts sessions with Session.config.secret. Session.configure and
SessionHandler require a usable secret only when it does. The default follows
encrypt_redis_data (RedisStore, ClusteredRedisStore); a store that never encrypts
returns false (MemoryStore), and one that always does returns true (CookieStore).
Regenerate session ID while preserving session data Important for security after authentication state changes