Stephan Schröder
02/28/2025, 12:32 PMget("/stream/{n}") {
call.respondBytes(
contentType = null,
status = HttpStatusCode.OK,
) {
ByteArrayOutputStream(64).apply {
repeat(3) {
write("Hello Bytes!".toByteArray())
}
}.toByteArray()
}
}
it outputs:
curl -X GET "<http://localhost:8081/stream/1>"
Hello Bytes!Hello Bytes!Hello Bytes!
but using respondBytesWrite
get("/stream/{n}") {
call.respondBytesWriter(
contentType = null,
status = HttpStatusCode.OK
) {
repeat(3) {
writeByteArray("Hello Bytes!".toByteArray())
}
}
}
leads to an empty response:
curl -X GET "<http://localhost:8081/stream/1>"
curl: (52) Empty reply from serve
but when I comment out the ContentNegotiation dependencies ktor-server-content-negotiation-jvm
and ktor-serialization-kotlinx-json-jvm
, it works again 🤷♂️
My ContentNegotiation config is pretty bare metal:
fun Application.configureSerialization() {
install(ContentNegotiation) {
json()
}
}
What am I missing?Aleksei Tirman [JB]
02/28/2025, 12:43 PMStephan Schröder
02/28/2025, 12:48 PMmadisp
02/28/2025, 12:50 PMmadisp
02/28/2025, 12:52 PMapplication/octet-stream
and 36
in this case (3x "Hello Bytes!" length)Stephan Schröder
02/28/2025, 12:54 PMmadisp
02/28/2025, 12:57 PMkotlinx-io-core-jvm
dependency a try, sounds like a bug with chunked transfer encoding due to thatmadisp
02/28/2025, 12:58 PMStephan Schröder
02/28/2025, 12:59 PMktor-serialization-kotlinx-json-jvm
with ktor-serialization-jackson-jvm
and that fixes it as well.Stephan Schröder
02/28/2025, 1:02 PMkotlinx-io-core-jvm
dependency fixes it as well! Thanks 👍