I'm trying to pipe a client response from the Ktor client library as a Ktor server response using the following code:
serviceClient.retrieveCourseZip(id, version).execute { response ->
call.respond(object : OutgoingContent.ReadChannelContent() {
override val contentType = response.contentType()
override val contentLength = response.contentLength()
override val status = response.status
override val headers = headersOf(
HttpHeaders.ContentDisposition to listOf("attachment; filename=\"course-$courseId.zip\"")
)
override fun readFrom() = response.content
})
}
response is a io.ktor.client.statement.HttpResponse returned by HttpStatement.execute.
The reason I'm doing this is that the backend service I'm developing with Ktor is a gateway that enforces authentication for clients coming from the open internet towards services that are behind this gateway.
Most of the time this code works nicely but I'm starting to have some weird behavior where clients that are downloading large amounts of data abruptly disconnect in the middle of the download due to unexpected end of stream errors on the client side. On the server side there are no error messages whatsoever and it looks like a graceful connection close.
Is there anything that is fundamentally broken with this code? I'm running this code in Amazon EKS environments where some have zero problems while others are absolutely broken.