ByteZ
04/11/2022, 9:11 PMon
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?if (rate.check()) {
proceed()
} else {
call.respond(HttpStatusCode.TooManyRequests)
finish()
}
Wrapped in pipeline.intercept(ApplicationCallPipeline.Setup)
Aleksei Tirman [JB]
04/12/2022, 11:01 AMIs there no way to access the pipeline context within the newThose details are hidden on purpose so there is no way.functions in plugins?on
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:
val plugin = createApplicationPlugin("plugin") {
onCall { call ->
if (!rate.check()) {
call.respond(HttpStatusCode.TooManyRequests)
}
}
}
That way the execution of pipeline isn’t finished.