Hello, I'm trying to convert a servlet-api filter...
# ktor
c
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
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.
requestDispatcher
, do you mean HTTP redirect? or just internally reroute a call to something else?
c
thanks for the finish() tip, that was what I was looking for
requestDispatcher does an internal forward, not a redirect
I guess, I could simultate this is Kotlin with a lambda called both from the routing and from the interceptor
thanks for help
o
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?
196 Views