https://kotlinlang.org logo
#ktor
Title
# ktor
m

Michael Waitt

07/25/2022, 6:17 PM
Hey folks 👋 Quick question on the new
createApplicationPlugin
API. More info in 🧵.
We currently have an interceptor in our ktor server that merges custom context data (if any) into the CoroutineContext on
ApplicationCallPipeline.Setup
.
Copy code
pipeline.intercept(customContextPhase) {
    val context = genContext(call)

    if (context != null) {
        withContext(context) {
            proceed()
        }
    } else {
        proceed()
    }
}
Since
withContext()
and
proceed()
are both not directly available to us in
createApplicationPlugin
's scope, do you have any recommendations on a way to achieve this same functionality? Or should we just stick with a pipeline interceptor in this case?
We did successfully create a custom
Hook
that basically does what this interceptor does. But this didn't feel quite right, as the hook ends up doing the plugin's heavy lifting.
a

Aleksei Tirman [JB]

07/26/2022, 7:45 AM
I think it’s OK to write a hook when you need low-level control over the execution.
🙏 1
2 Views