Since apparently routes have their own pipeline (<...
# ktor
f
Since apparently routes have their own pipeline (https://ktor.io/advanced/pipeline/route.html), is it possible to install a feature on a route's pipeline? I tried doing something like
Copy code
route("/foo", HttpMethod.Get) {
            install(ExampleFeature)
            handle {...}
}
However the feature appears to run for all routes.
b
What does the feature do? You can
Route.intercept
stages specific to a route, but
Application.install
will always be scoped to the entire application
o
If
ExampleFeature
is defined for an
Application
, you can’t install it into a
Route
. Unfortunately, we didn’t find a way to issue an error or a warning, when this happens. DslMarker is not powerful enough in this case.
If you want it to work with
Routes
, a feature should be implemented for
ApplicationCallPipeline
f
Thanks for the reply. My feature was in indeed implementing
ApplicationFeature<Application, ...>
and not
ApplicationFeature<ApplicationCallPipeline, ...>
. By switching to the last one I get the expected behaviour: the feature interceptor only runs if the request goes to the route where it was installed.
When I had my feature implementing
ApplicationFeature<Application, ...>
, there was no error during install and the interceptor ran for all requests, which was surprising.
o
That’s because it got attached to the receiver of the outer lambda (or function). There is
DslMarker
mechanics in the language, but unfortunately it is not enough in this case