Hey folks! We’re trying to log the request payload...
# ktor
c
Hey folks! We’re trying to log the request payload (using
CallLogging
and
DoubleReceive
):
Copy code
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 to 
RequestAlreadyConsumedException
 error unless you have DoubleReceive feature installed.
https://ktor.io/servers/calls/requests.html#receiving-several-times
Exception:
Copy code
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.
t
You need to set
receiveEntireContent
to
true
.
Copy code
install(DoubleReceive) {
    receiveEntireContent = true
}
That solved the problem for me. However, any hints from a ktor-developer would be greatly appreciated.