-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
KTOR-7194 Deferred session fetching for public endpoints #4609
base: main
Are you sure you want to change the base?
Conversation
38f8ec5
to
9e7c373
Compare
9e7c373
to
0f5ad71
Compare
* | ||
* Note: this is only available for JVM in Ktor 3.0 | ||
*/ | ||
public var deferred: Boolean = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would mark it with OptIn and look for a better explaining name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should have a system property (like io.ktor.server.sessions.lazycreate
) for this instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, this way we don't need to change the API 👍
...rver/ktor-server-plugins/ktor-server-sessions/common/src/io/ktor/server/sessions/Sessions.kt
Outdated
Show resolved
Hide resolved
.../ktor-server-sessions/jvmAndPosix/src/io/ktor/server/sessions/BlockingDeferredSessionData.kt
Outdated
Show resolved
Hide resolved
/** | ||
* When set to true, sessions will be lazily retrieved from storage. | ||
* | ||
* Note: this is only available for JVM in Ktor 3.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For JVM and Native?
import kotlin.test.assertEquals | ||
import kotlin.test.assertFailsWith | ||
|
||
class SessionAuthJvmTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't this test be moved to the jvmAndPosix
source-set?
assertFailsWith<IllegalStateException> { | ||
client.get("/authenticated", withCookie).status | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also add a successful call after the failed one? Maybe move one of the calls made above
…c/io/ktor/server/sessions/Sessions.kt Co-authored-by: Osip Fatkullin <[email protected]>
…ix/src/io/ktor/server/sessions/BlockingDeferredSessionData.kt Co-authored-by: Osip Fatkullin <[email protected]>
Subsystem
Server, Sessions
Motivation
KTOR-7194 SessionStorage.read() is called for non-authenticated routes and static assets
Solution
This change provides an option in the sessions configuration
deferred = true
that defers session retrieval until it is used in the request.This works by introducing a
CurrentSession
implementation that uses lazy retrieval to avoid unnecessary calls to the backing storage.