Required dependencies: io.ktor:%artifact_name%
The %plugin_name% 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 %plugin_name%
to log a request body using the CallLogging plugin and then receive a body one more time inside the post
route handler.
The
%plugin_name%
plugin uses an experimental API that is expected to evolve in the upcoming updates with potentially breaking changes.
{type="note"}
After installing %plugin_name%
, 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...
{src="snippets/double-receive/src/main/kotlin/com/example/Application.kt" include-lines="16-23"}
... and then get a request body one more time inside a route handler.
{src="snippets/double-receive/src/main/kotlin/com/example/Application.kt" include-lines="25-28"}
You can find the full example here: double-receive.
With the default configuration, %plugin_name%
provides the ability to receive a request body as the following types:
ByteArray
String
Parameters
- data classes used by the
ContentNegotiation
plugin
By default, %plugin_name%
doesn't support:
- receiving different types from the same request;
- receiving a stream or channel.
Set the cacheRawRequest
property to false
, if you do not need to receive different types from the same request or receive a stream or channel:
install(DoubleReceive) {
cacheRawRequest = false
}