I'm trying to upgrade from 1.6.8 to 2.2.1 and ran ...
# ktor
t
I'm trying to upgrade from 1.6.8 to 2.2.1 and ran into a problem I don't see how to solve. My 1.6.8 code has it's own session tracker class based on SessionTrackerById. When there are multiple requests with an expired session id, this tracker gives all those requests the same new session id. I use this feature to provide a "re-login" functionality for the users where the requests are automatically repeated after the user provides the credentials. Imagine a big-big form the user filled and after 30 mins he clicked on submit. Now, I don't want to force the user to fill the form again, also I don't want to manage all the states on client side for each form. It is so simple to relog the user and send in the form again. This can be handled in low level communication code, no need to make business code more complicated. This worked because I've been able to change the session tracker during configuration. Now with the new "reified builder" based approach I can't find a way to provide my own session tracker. Any suggestions apart "don't use sessions that way"?
a
Could you please share the relevant code for Ktor 1.6.8?
t
The problematic part, see link to full code below, it's open source.
Copy code
override fun configure(conf: Sessions.Configuration) {
        with(conf) {
            val sessionType = StackSession::class

            val name = with(server.settings.ktor) {
                if (portCookie) "ZKL_SESSION_$port" else "ZKL_SESSION"
            }

            @Suppress("DEPRECATION") // as in Ktor code
            val builder = CookieIdSessionBuilder(sessionType).apply {
                cookie.path = "/"
            }
            val transport = SessionTransportCookie(name, builder.cookie, builder.transformers)
            val tracker = RenewableSessionTrackerById(sessionType, StackSessionSerializer, SessionStorageSql, builder.sessionIdProvider)
            val provider = SessionProvider(name, sessionType, transport, tracker)
            register(provider)

            SessionMaintenanceTask.start()
        }
    }
https://github.com/spxbhuhb/zakadabar-stack/blob/master/lib/accounts/src/jvmMain/kotlin/zakadabar/lib/accounts/business/KtorSessionBl.kt
a
Unfortunately, I see only one option to create an instance of the
CookieIdSessionBuilder
class via reflection.