Hello!
Is it possible to have a custom plugin act as a “middleware” that can abort the whole pipeline(the request) ?
Our use-case:
After the “validate { }” function, we need to check whether our user has “profile completed” status (by checking his claims on the JWT), and if not - respond with some status.
But validate itself only has 2 options (if principal is null -> it returns 401, otherwise it just proceeds).
And if I implement a custom plugin, even if I do there “call.respond(..)” it still proceeds to other plugins instead of finishing the whole pipeline
I elaborated more on it here :
https://stackoverflow.com/questions/74243213/how-to-stop-pipeline-in-ktors-plugins-middleware-that-sends-a-response-and-abo
r
Ron S
10/29/2022, 10:56 AM
I'm no expert, but I could imagine that the rest of the pipeline is aborted when response.pipeline.execute is called. So, try calling call.respond instead of just setting the status code.
e
Eli
10/29/2022, 11:04 AM
Hi Ron,
Yes that’s what I’m doing : “call.respond”
(** we use “call.respondWith(..)” which is some extension we made that wraps the “call.respond”)
I think there’s “finish()” function on the pipeline, but I can’t seem to have any access to it from the custom Plugins or even the “validate” block.
r
Ron S
10/29/2022, 11:15 AM
I thought the wrapper only sets the response code and thus not invokes pipeline.execute. I'm afraid I can't help you then.