https://kotlinlang.org logo
#ktor
Title
# ktor
b

brabo-hi

03/12/2024, 6:32 PM
Hello guys, what is the best way to validate headers for all requests and returning a customer response?
one way could be to
createApplicationPlugin
but in that case we can only throw exception instead of returning body
Copy code
val HeaderValidatorPlugin = createApplicationPlugin("HeaderValidatorPlugin") {
    on(CallSetup) { call ->
        if (!call.request.headers.contains("X-Customer-Header")) {
            throw BadRequestException("Required header is missing")
        }
a

Aleksei Tirman [JB]

03/12/2024, 9:10 PM
What prevents sending the response with the
ApplicationCall.respond
method?