Another question - I'm porting code from ktor 1, a...
# ktor
j
Another question - I'm porting code from ktor 1, and there's a unit test that tests that some code that uses ktor's HttpClient executes properly. Previously the request.body it would pass to the MockEngine would be of type
TextContent
, so the test could inspect it to make sure it had the right content. With ktor 2, however, the request.body is an
OutputStreamContent
- what's the best way for me to verify that its content is correct?
h
response.bodyAsText()
j
This is a request not a response.
h
Oh, sorry, missed it.
j
It looks like
Copy code
suspend fun OutputStreamContent.asText(): String =
    String(ByteChannel().also { writeTo(it) }.toByteArray(), Charsets.UTF_8)
works, but is there a cleaner way?
h
Your could use
.body.toByteReadPacket().readText()
instead, but don't know, which is better 😄
j
That version doesn't make me presume that the type of
body
is
OutputStreamContent
, so it seems better. Thanks!
h
And it does not enforce utf-8
j
Indeed - presumably it picks up the right encoding from the request?
h
Yes, from the data
j
Great