RequestSession class
Manages HTTP sessions for the Khadem framework.
This class provides a clean interface for session management, wrapping the raw HttpSession with additional utilities and security features.
Constructors
- RequestSession(HttpRequest _request)
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- isSessionEmpty → bool
-
Checks if the session is empty.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- sessionId → String
-
Gets the session ID.
no setter
- sessionKeys → Iterable
-
Gets all session keys.
no setter
- sessionLength → int
-
Gets the number of items in the session.
no setter
Methods
-
cleanup(
) → void - Cleans up expired flash data and performs maintenance.
-
clear(
) → void - Clears all session data.
-
destroy(
) → void - Destroys the current session.
-
flash(
String key, dynamic value) → void - Flashes a value to the session (temporary, removed after next access).
-
flush(
) → void - Alias for clear.
-
forget(
String key) → void - Alias for remove.
-
get(
String key, [dynamic defaultValue]) → dynamic - Gets a value from the session by key.
-
getAge(
) → Duration - Gets the session age.
-
getAllData(
) → Map< String, dynamic> - Gets all session data as a map (excluding internal metadata).
-
getCreatedAt(
) → DateTime? - Gets the session creation time.
-
getFlashedData(
) → Map< String, dynamic> - Gets all flashed data and clears them.
-
getLastAccess(
) → DateTime? - Gets the last access time of the session.
-
getStats(
) → Map< String, dynamic> - Gets session statistics.
-
getTimeout(
) → Duration? - Gets the session timeout if set.
-
getTimeUntilExpiration(
) → Duration? - Gets the remaining time before session expires.
-
getTyped<
T> (String key, [T? defaultValue]) → T? - Gets a typed value from the session, with optional default.
-
has(
String key) → bool - Checks if a key exists in the session.
-
hasFlashedData(
) → bool - Checks if the session has any flashed data.
-
invalidate(
) → void - Forces session invalidation.
-
isExpired(
) → bool - Checks if the session has expired based on timeout.
-
isExpiringSoon(
[Duration within = const Duration(minutes: 5)]) → bool - Checks if the session is about to expire within the given duration.
-
isInvalidated(
) → bool - Checks if the session has been invalidated.
-
isValid(
) → bool - Validates the session based on timeout and other security checks.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
pull(
String key, [dynamic defaultValue]) → dynamic - Retrieves and removes a value from the session.
-
put(
String key, dynamic value) → void - Alias for set.
-
regenerateId(
) → void - Regenerates the session ID for security.
-
remove(
String key) → void - Removes a key from the session.
-
set(
String key, dynamic value) → void - Sets a value in the session.
-
setMultiple(
Map< String, dynamic> data) → void - Sets multiple values in the session at once.
-
setTimeout(
Duration timeout) → void - Sets the session timeout.
-
shouldRegenerate(
{Duration maxAge = const Duration(hours: 1)}) → bool - Checks if the session should be regenerated (security best practice).
-
toString(
) → String -
A string representation of this object.
inherited
-
touch(
) → void - Touches the session to update last access time.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited