Is there no way to access the pipeline context wit...
# ktor
b
Is there no way to access the pipeline context within the new
on
functions in plugins? Do I simply not have to call
finish
and
proceed
anymore? Will ktor automatically detect that the request has already received a response and not pass it further down the pipeline?
For a bit more context: I have a RateLimiter feature in ktor 1.6 that works like this:
Copy code
if (rate.check()) {
    proceed()
} else {
    call.respond(HttpStatusCode.TooManyRequests)
    finish()
}
Wrapped in
pipeline.intercept(ApplicationCallPipeline.Setup)
a
Is there no way to access the pipeline context within the new
on
functions in plugins?
Those details are hidden on purpose so there is no way.
Will ktor automatically detect that the request has already received a response and not pass it further down the pipeline?
Most of Ktor standard plugins like
Routing
work only if a response isn’t already sent so you can rewrite your code in the following way:
Copy code
val plugin = createApplicationPlugin("plugin") {
    onCall { call ->
        if (!rate.check()) {
            call.respond(HttpStatusCode.TooManyRequests)
        }
    }
}
That way the execution of pipeline isn’t finished.
👍 1