Hi, I am experimenting with the `<http://kotlinx.i...
# ktor
a
Hi, I am experimenting with the
<http://kotlinx.io|kotlinx.io>
library in Ktor 3, but having this issue:
Copy code
call.respondSource(
   source = asset.output.source, // <--- this is a Source
   contentType = asset.output.contentType
)
This returns an EMPTY response.
Copy code
call.respondBytes(
    bytes = asset.output.source.readByteArray(),
    contentType = asset.output.contentType
)
This doesn't. This hardly makes sense to me. When I set a breakpoint in the first example before the respondSource and run the following expression:
asset.output.source.readText()
I ge the full text (once, of course).
Okay, so in tests it works, but not in a real application. I filed a bug including a very minimal reproducer: https://youtrack.jetbrains.com/issue/KTOR-7683/call.respondSource-returns-empty-response-but-passes-in-tests It is very worrying to me that the tests behave differently than running an actual browser.
b
Hey, it looks like
respondSource
relies on
Source.transferFrom
which expects the input to be fully buffered into memory. I'm not sure if this was a mistake in Ktor's use of kotlinx-io or an issue in kotlinx-io itself. I added a workaround in the ticket using
Buffer
, which is not ideal, but we ought to fix the problem for the next patch release.
a
Great. But why would it work in a test then?
b
there's gotta be something in the pipeline that lets the inputstream buffer it's content before hitting the transfer
a
That makes sense. The
testApplication
is completely different Engine than Netty ofcourse.