https://kotlinlang.org logo
Title
b

ByteZ

01/26/2022, 4:17 PM
Hey guys! Is there a better way to receive a UTF-8 String from a post request than
call.receive<ByteArray>().toString(Charsets.UTF_8)
? I'm aware that
call.receiveText()
exists but we had some encoding issues after receiving a request containing a "Fullwidth Colon" (U+FF1A).
a

Aleksei Tirman [JB]

01/27/2022, 10:44 AM
Could you please post an example of the response body?
b

ByteZ

01/27/2022, 8:17 PM
a

Aleksei Tirman [JB]

01/28/2022, 9:12 AM
The problem is that since a client doesn't specify an encoding in the
Content-Type
header, the assumed content encoding is
Charsets.ISO_8859_1
. Here is the issue about it https://youtrack.jetbrains.com/issue/KTOR-789.
b

ByteZ

01/28/2022, 4:26 PM
The issue seems pretty stale. Maybe adding a function like
call.receiveText(charset: Charset)
would be easier?
a

Aleksei Tirman [JB]

01/28/2022, 6:44 PM
The fix was made today and will be available in Ktor 2.0.0. Having a
charset
parameter is a good option but the implementation isn't going be easy.
b

ByteZ

01/28/2022, 8:26 PM
Thanks for the quick fix!