The DoubleReceive plugin provides the ability to receive a request body several times with no
RequestAlreadyConsumedException exception. This might be useful if a plugin is already consumed a request body, so you cannot receive it inside a route handler. For example, you can use
DoubleReceive to log a request body using the CallLogging plugin and then receive a body one more time inside the
post route handler.
DoubleReceive, you need to include the
ktor-server-double-receive artifact in the build script:
... inside the
... inside the explicitly defined
module, which is an extension function of the
DoubleReceive plugin can also be installed to specific routes. This might be useful if you need different
DoubleReceive configurations for different application resources.
DoubleReceive, you can receive a request body several times and every invocation returns the same instance. For example, you can enable logging of a request body using the CallLogging plugin...
... and then get a request body one more time inside a route handler.
You can find the full example here: double-receive.
With the default configuration,
DoubleReceive provides the ability to receive a request body as the following types:
data classes used by the
DoubleReceive doesn't support:
receiving different types from the same request;
receiving a stream or channel.
cacheRawRequest property to
false, if you do not need to receive different types from the same request or receive a stream or channel: