post("/oauth/token") {
val gt = call.parameters.get("grant_type") ?: call.respond(HttpStatusCode.BadRequest, mapOf("error" to "no grant_type specified"));
call.respondText(call.request.headers["Authorization"] ?: "No header")
}
how to response and return to avoid run the second response?
s
spand
01/30/2020, 10:44 AM
Something like this?
Copy code
post("/oauth/token") {
param("grant_type") {
handle {
val gt = call.parameters.get("grant_type")!! call.respond(HttpStatusCode.BadRequest, mapOf("error" to "no grant_type specified"));
call.respondText(call.request.headers["Authorization"] ?: "No header")
}
}
}
y
Yyq2008
01/30/2020, 12:27 PM
No, I want just want to finish the response if no grant type found.
Yyq2008
01/30/2020, 12:46 PM
Thanks, I found the solution:
Copy code
post("/oauth/token") {
val gt = call.parameters.get("grant_type") ?: run {
call.respond(
HttpStatusCode.BadRequest,
mapOf("error" to "no grant_type specified")
);
return@post
}
call.respondText(call.request.headers["Authorization"] ?: "No header")
}