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

Felix

04/14/2019, 9:18 PM
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

bdawg.io

04/14/2019, 9:52 PM
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

orangy

04/14/2019, 10:20 PM
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

Felix

04/15/2019, 9:55 PM
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

orangy

04/16/2019, 8:14 AM
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
3 Views