hellman
05/12/2025, 7:13 AMsse()
routes. If we want to send a HTTP response instead of emitting events (e.g., call.respond(HttpStatusCode.BadRequest)
), that response code is simply ignored and we always get HTTP 200. Is this an expected behavior? I feel it makes error handling for SSE endpoints difficult.Aleksei Tirman [JB]
05/12/2025, 8:43 AMhellman
05/12/2025, 8:49 AMhellman
05/12/2025, 8:52 AMAleksei Tirman [JB]
05/12/2025, 8:53 AMhellman
05/12/2025, 9:23 AMhellman
05/12/2025, 9:24 AMAleksei Tirman [JB]
05/12/2025, 9:54 AMSSEServerContent
class to initiate an SSE session. Here is an example:
routing {
get("/sse") {
try {
external()
call.response.header(HttpHeaders.ContentType, ContentType.Text.EventStream.toString())
call.response.header(HttpHeaders.CacheControl, "no-store")
call.response.header(HttpHeaders.Connection, "keep-alive")
call.response.header("X-Accel-Buffering", "no")
call.respond(SSEServerContent(call) {
send(ServerSentEvent("Hello client!"))
})
} catch (_: RuntimeException) {
call.respond(HttpStatusCode.InternalServerError)
}
}
}
// ...
suspend fun external() {
// throw RuntimeException("error")
}
hellman
05/12/2025, 9:57 AM