Constantin Muraru
09/11/2020, 9:21 AMCallLogging
and DoubleReceive
):
install(DoubleReceive)
install(CallLogging) {
level = <http://Level.INFO|Level.INFO>
format { callFormatterAsCurlCommand(it) }
}
fun callFormatterAsCurlCommand(call: ApplicationCall): String {
val payload = runBlocking { call.receiveText() }
return payload
}
However, we receive the Request body has been already consumed
error, which is rather unexpected. Furthermore, the error is thrown by the DoubleReceive.kt
class itself.
The docs even say:
All the receive methods consume the whole payload sent by the client so an attempt to receive a request body twice will lead toerror unless you have DoubleReceive feature installed.RequestAlreadyConsumedException
https://ktor.io/servers/calls/requests.html#receiving-several-timesException:
io.ktor.request.RequestAlreadyConsumedException: Request body has been already consumed (received).
at io.ktor.features.DoubleReceive$Feature$install$1.invokeSuspend(DoubleReceive.kt:93) ~[ktor-server-core-jvm-1.4.0.jar:1.4.0]
at io.ktor.features.DoubleReceive$Feature$install$1.invoke(DoubleReceive.kt) ~[ktor-server-core-jvm-1.4.0.jar:1.4.0]
at io.ktor.util.pipeline.SuspendFunctionGun.loop(PipelineContext.kt:323) ~[ktor-utils-jvm-1.4.0.jar:1.4.0]
Any tips gladly appreciated.Tobias Marschall
09/14/2020, 6:05 AMreceiveEntireContent
to true
.
install(DoubleReceive) {
receiveEntireContent = true
}
That solved the problem for me. However, any hints from a ktor-developer would be greatly appreciated.