Hello,
I'm trying to convert a servlet-api filter to ktor.
The relevant code is:
Copy code
if (AngularForwardingSelector.shouldForward(requestURI)) {
val requestDispatcher = request.getRequestDispatcher(forwardToUrl)
requestDispatcher.forward(request, response)
} else {
chain.doFilter(request, response)
}
Trying the conversion, I have 2 questions:
- does ktor have around intercerptors? If not, is there a way to stop pipeline from continuing in a before interceptor?
- does kotlin have something similar to request dispatcher (for internal forwarding)?
I tried looking into interceptors, but the documentation is slim, and I can't figure it out how to make it work.
o
orangy
09/21/2018, 12:36 PM
interceptors
are core to #ktor, so absolutely yes. Please check https://ktor.io/advanced/pipeline.html for some details. But basically you need to choose a phase, install interceptor and call
finish
if you want to stop the pipeline.
orangy
09/21/2018, 12:37 PM
requestDispatcher
, do you mean HTTP redirect? or just internally reroute a call to something else?
c
cvmocanu
09/21/2018, 1:57 PM
thanks for the finish() tip, that was what I was looking for
cvmocanu
09/21/2018, 1:57 PM
requestDispatcher does an internal forward, not a redirect
cvmocanu
09/21/2018, 1:58 PM
I guess, I could simultate this is Kotlin with a lambda called both from the routing and from the interceptor
cvmocanu
09/21/2018, 1:58 PM
thanks for help
o
orangy
09/21/2018, 2:04 PM
We actually want to do something like internal redirect, but lacked real use cases. Could you explain what and why do you need to redirect?