Package io.ktor.sessions

Types

Cache

interface Cache<in K : Any, V : Any>

CacheStorage

class CacheStorage : SessionStorage

CookieConfiguration

class CookieConfiguration

Cookie configuration being used to send sessions

CookieIdSessionBuilder

class CookieIdSessionBuilder<S : Any> : 
    CookieSessionBuilder<S>

Cookie session configuration builder

CookieSessionBuilder

open class CookieSessionBuilder<S : Any>

Cookie session configuration builder

CurrentSession

interface CurrentSession

Represents a container for all session instances

HeaderIdSessionBuilder

class HeaderIdSessionBuilder<S : Any> : 
    HeaderSessionBuilder<S>

Header session configuration builder

HeaderSessionBuilder

open class HeaderSessionBuilder<S : Any>

Header session configuration builder

SessionProvider

class SessionProvider

Specifies a provider for a session with the specific name and type

SessionSerializer

interface SessionSerializer

Serializes session from and to String

SessionSerializerReflection

class SessionSerializerReflection<T : Any> : 
    SessionSerializer

Default reflection-based session serializer that does it via reflection. Serialized format is textual and optimized for size as it is could be transferred via HTTP headers or cookies

SessionStorage

interface SessionStorage

Represents a way to write, read and invalidate session bits.

SessionStorageMemory

class SessionStorageMemory : SessionStorage

SessionStorage that stores session contents into memory.

SessionTracker

interface SessionTracker

SessionTracker provides ability to track and extract session from the call context.

SessionTrackerById

class SessionTrackerById : SessionTracker

SessionTracker that transfers a Session Id generated by a sessionIdProvider in HTTP Headers/Cookies. It uses a storage and a serializer to store/load serialized/deserialized session content of a specific type.

SessionTrackerByValue

class SessionTrackerByValue : SessionTracker

SessionTracker that stores the contents of the session as part of HTTP Cookies/Headers. It uses a specific serializer to serialize and deserialize objects of type type.

SessionTransport

interface SessionTransport

SessionTransport receive, send or clear a session from/to an ApplicationCall.

SessionTransportCookie

class SessionTransportCookie : SessionTransport

SessionTransport that adds a Set-Cookie header and reads Cookie header for the specified cookie name, and a specific cookie configuration after applying/un-applying the specified transforms defined by transformers.

SessionTransportHeader

class SessionTransportHeader : SessionTransport

SessionTransport that sets or gets the specific header name, applying/un-applying the specified transforms defined by transformers.

SessionTransportTransformer

interface SessionTransportTransformer

Represents a session cookie transformation. Useful for such things like signing and encryption

SessionTransportTransformerDigest

class SessionTransportTransformerDigest : 
    SessionTransportTransformer

Session transformer that appends an algorithm hash of the input. Where the input is either a session contents or a previous transformation. It prepends a salt when computing the hash.

SessionTransportTransformerEncrypt

class SessionTransportTransformerEncrypt : 
    SessionTransportTransformer

Session transformer that encrypts/decrypts the input.

SessionTransportTransformerMessageAuthentication

class SessionTransportTransformerMessageAuthentication : 
    SessionTransportTransformer

Session transformer that appends an algorithm MAC (Message Authentication Code) hash of the input. Where the input is either a session contents or a previous transformation. It uses a specified keySpec when generating the Mac hash.

Sessions

class Sessions

Sessions reature that provides a mechanism to persist information between requests.

Exceptions

TooLateSessionSetException

class TooLateSessionSetException : IllegalStateException

This exception is thrown when HTTP response has been already sent but an attempt to modify session is made

Extensions for External Classes

kotlin.collections.List

Properties

sessions

Get current session or fail if no session feature installed

Functions

autoSerializerOf

fun <T : Any> autoSerializerOf(): SessionSerializerReflection<T>

Creates the the default SessionSerializer for type T

fun <T : Any> autoSerializerOf(
    type: KClass<T>
): SessionSerializerReflection<T>

Creates the the default SessionSerializer for class type

clear

fun <T> CurrentSession.clear(): Unit

Clear session instance with type T

cookie

fun <S : Any> Configuration.cookie(
    name: String,
    sessionType: KClass<S>,
    storage: SessionStorage
): Unit
fun <S : Any> Configuration.cookie(
    name: String,
    storage: SessionStorage
): Unit
fun <S : Any> Configuration.cookie(
    name: String,
    sessionType: KClass<S>,
    storage: SessionStorage,
    block: CookieIdSessionBuilder<S>.() -> Unit
): Unit

Configure sessions to get it from cookie using session storage

fun <S : Any> Configuration.cookie(
    name: String,
    storage: SessionStorage,
    block: CookieIdSessionBuilder<S>.() -> Unit
): Unit

Configures a session using a cookie with the specified name using it as a session id. The actual content of the session is stored at server side using the specified storage. The cookie configuration can be set inside block using the cookie property exposed by CookieIdSessionBuilder.

fun <S : Any> Configuration.cookie(
    name: String,
    sessionType: KClass<S>
): Unit
fun <S : Any> Configuration.cookie(name: String): Unit

Configure sessions to serialize to/from HTTP cookie

fun <S : Any> Configuration.cookie(
    name: String,
    block: CookieSessionBuilder<S>.() -> Unit
): Unit

Configures a session using a cookie with the specified name using it as for the actual session content optionally transformed by specified transforms in block. The cookie configuration can be set inside block using the cookie property exposed by CookieIdSessionBuilder.

fun <S : Any> Configuration.cookie(
    name: String,
    sessionType: KClass<S>,
    block: CookieSessionBuilder<S>.() -> Unit
): Unit

Configure sessions to serialize to/from HTTP cookie configuring it by block

directorySessionStorage

fun directorySessionStorage(
    rootDir: File,
    cached: Boolean = true
): SessionStorage

Creates a session storage that serializes them into regular files under the specified rootDir

get

fun <T> CurrentSession.get(): T?

Get session instance with type T

getOrSet

fun <T> CurrentSession.getOrSet(
    name: String = findName(T::class),
    generator: () -> T
): T

Get or generate a new session instance using generator with type T (or name if specified)

header

fun <S : Any> Configuration.header(
    name: String,
    sessionType: KClass<S>,
    storage: SessionStorage
): Unit
fun <S : Any> Configuration.header(
    name: String,
    storage: SessionStorage
): Unit

Configure sessions to get it from HTTP header using session storage

fun <S : Any> Configuration.header(
    name: String,
    storage: SessionStorage,
    block: HeaderIdSessionBuilder<S>.() -> Unit
): Unit
fun <S : Any> Configuration.header(
    name: String,
    sessionType: KClass<S>,
    storage: SessionStorage,
    block: HeaderIdSessionBuilder<S>.() -> Unit
): Unit

Configures a session using a header with the specified name using it as a session id. The actual content of the session is stored at server side using the specified storage.

fun <S : Any> Configuration.header(
    name: String,
    sessionType: KClass<S>
): Unit
fun <S : Any> Configuration.header(name: String): Unit

Configure sessions to serialize to/from HTTP header

fun <S : Any> Configuration.header(
    name: String,
    block: HeaderSessionBuilder<S>.() -> Unit
): Unit

Configures a session using a header with the specified name using it for the actual session content optionally transformed by specified transforms in block.

fun <S : Any> Configuration.header(
    name: String,
    sessionType: KClass<S>,
    block: HeaderSessionBuilder<S>.() -> Unit
): Unit

Configures a session using a header with the specified name using it for the actual session content and apply block function to configure serializataion and optional transformations

set

fun <T> CurrentSession.set(value: T?): Unit

Set session instance with type T