Vinicius Carvalho
03/26/2019, 2:58 PMHow to intercept preventing additional executions
its not clear where that intercept
function belongs to. Could someone care to explain how to add an interceptor to any route that could prevent the pipeline to continue (verifying a header)Michael Pearce
03/27/2019, 4:25 AMfun Route.requireHeaders(vararg headerNames: String) {
intercept(ApplicationCallPipeline.Call) {
val request = call.request
headerNames.forEach { requiredHeader ->
if (request.header(requiredHeader) == null) {
call.respond(HttpStatusCode.BadRequest)
finish()
return@intercept
}
}
}
}
And then used it in the routes like:
route("/some_path") {
requireHeaders("X-Some-Header", "X-Some-Other-Header")
get { call.respond(...) }
}