Is it possible to send a chunked response with kto...
# ktor
r
Is it possible to send a chunked response with ktor-server? Here is what it looks like in vertx:
Copy code
val response = request.response()
val channel = response.toSendChannel(vertx)

response.headers().set("Transfer-Encoding", "chunked")

for (i in 1..10) {
  delay(200)
  channel.send(Buffer.buffer("""{"id": $i}"""))
  channel.send(Buffer.buffer("\n"))
}

response.end().await()
a
Yes. You can use the
ApplicationCall.respondBytesWriter
method:
Copy code
embeddedServer(Netty, port = 3333) {
    routing {
        get("/") {
            call.respondBytesWriter {
                for (i in 1..10) {
                    delay(200)
                    writeStringUtf8("""{"id": $i}""")
                    writeStringUtf8("\n")
                    flush()
                }
            }
        }
    }
}.start(wait = true)
r
Thanks a lot. I forgot to flush. Again...
😆 1