Hello. We encountered a scenario with routes and i...
# ktor
a
Hello. We encountered a scenario with routes and interceptors that seems weird. Please consider the scenario below:
Copy code
fun Route.routeA() = route("/a") {
  intercept(ApplicationCallPipeline.Call) {
    <do_something_a>
  }
}

fun Route.routeB() = route("/a/{some_value}") {
  intercept(ApplicationCallPipeline.Call) {
    <do_something_b>
  }
}

routing {
  routeB()
  routeA()
}
When we send a request to
/a/some_value
, the request goes through
do_something_a
first before
do_something_b
. Is this the expected behavior? Our expectation is that only
do_something_b
would be triggered, since in this case
routeB
is not a child route of
routeA
Note: We separated the routes due to the hope that the interceptor will only be applied to the enclosing route. We have some business requirement where ACL is different on those scenarios
b
I don't think intercepts work in a conditional fashion like that. If you want to do something like ACL, then I'd suggest building an PermissionsFeature or similar that intercepts on the Pipeline once, and populates the call (or use the AuthContext with the info you need). Then have a helper function as a filter you can call directly inside each route (where your intercepts are now) that calculates whether to proceed or throw some permissions exception
👍 1