sendJson

private fun sendJson(ex: HttpExchange, status: Int, body: JsonObject)

Chunked, not buffered: toJson(body) materializes the document as a String and again as a byte[], and a String also caps how large a response can ever be. Fixing the status at the first byte only costs a 500 an OOM here could not have sent anyway. Orthogonal to SSE — the content type still selects the client's non-SSE path.