mbonnin
09/04/2022, 10:13 PMhfhbd
09/05/2022, 10:04 AMimport io.ktor.client.*
import io.ktor.client.request.*
import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.cio.*
import io.ktor.server.engine.*
import io.ktor.server.plugins.statuspages.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import kotlinx.coroutines.*
suspend fun main(): Unit = coroutineScope {
embeddedServer(CIO) {
install(StatusPages) {
exception<IllegalStateException> { call, cause ->
println(cause)
}
status(HttpStatusCode(418, "I'm a teapot")) { call, status ->
println(status)
}
}
routing {
get {
call.respondText {
"Hello World"
}
}
route("test") {
get {
call.respondText {
error("TESTING")
}
}
}
get("teapot") {
call.respond(HttpStatusCode(418, "I'm a teapot"))
}
get("tea") {
call.respondText { HttpClient(io.ktor.client.engine.cio.CIO).get("<http://localhost/teapot>").status.toString() }
}
}
}.start(wait = true)
}
If you call /tea or /teapot the status 418 is printed, but you still get an answer.mbonnin
09/05/2022, 10:08 AMmbonnin
09/05/2022, 10:09 AMmbonnin
09/05/2022, 10:09 AMhfhbd
09/05/2022, 10:12 AM