Hi, In my application that is running on top of Kt...
# ktor
Hi, In my application that is running on top of Ktor 1.6.4 I noticed that call.receiveText() returns a garbled string if the input text is in Japanese. I ruled out that it happens on the client side. Is there some configuration I forgot to do to make receiveText handle Japanese correctly?
Could you please try to reproduce it with Ktor 1.6.8 or 2.0.2?
Still garbled with 1.6.8
Any idea what do to next @Aleksei Tirman [JB] ?
Seems like there is some bug in Ktor 1.6.8 that is fixed in Ktor 2.0.2.
Can you please send a link to the bug?
Most likely this one https://youtrack.jetbrains.com/issue/KTOR-789. As a workaround, use the following code to receive a body as text:
Copy code
import io.ktor.application.*
import io.ktor.features.*
import io.ktor.http.*
import io.ktor.request.*
import io.ktor.routing.*
import io.ktor.server.engine.*
import io.ktor.server.netty.*
import io.ktor.utils.io.*
import io.ktor.utils.io.core.*

fun main() {
    embeddedServer(Netty, port = 3333) {
        routing {
            post("/") {
                val charset = try {
                    call.request.contentCharset() ?: Charsets.UTF_8
                } catch (cause: BadContentTypeFormatException) {
                    throw BadRequestException("Illegal Content-Type format: ${call.request.headers[HttpHeaders.ContentType]}", cause)
                val text = call.receiveChannel().readRemaining().readText(charset)
Thanks I will try that.
Is it possible to add the fix for Ktor 1.6.x at some point?
Unfortunately, no. Only security bug fixed are backported into Ktor 1.6.*.