DoubleReceive
feature provides the ability to invoke ApplicationCall.receive
several times with no RequestAlreadyConsumedException
exception. This usually makes sense when a feature is consuming a request body so a handler is unable to receive it again.
Install DoubleReceive
feature into the ApplicationCall
After that you can receive from a call multiple times and every invocation may return the same instance.
Types that could be always received twice with this feature are: ByteArray
, String
and Parameters
and all types provided by ContentNegotiation feature (for example, objects deserialized from JSON payloads).
Receiving different types from the same call is not guaranteed to work without but may work in some specific cases. For example, receiving a text after receiving a byte array always works.
When receiveEntireContent
is enabled, then receiving different types should always work. Also double receive of a channel or stream works as well. However, receive
executes the whole receive pipeline from the beginning so all content transformations and converters are executed every time that may be slower than with the option disabled.
If a custom content transformation is installed (for example, by intercepting receive pipeline), then a transformed value couldn’t be re-received without receiveEntireContent
option by default. However it is possible to mark a transformed value object as reusable by specifying option:
receiveEntireContent
When enabled, for every request the whole content will be received and stored as a byte array. This is useful when completely different types need to be received. You also can receive streams and channels. Note that enabling this causes the whole receive pipeline to be executed for every further receive pipeline.