MissingRequestContent error & large body buffering in Ktor
0 reputation · 11 Nov 2023, 02:14 UTC
MissingRequestContent error & large body buffering in Ktor
Ktor buffers the entire request body by default when call.receive is used. For payloads larger than a few megabytes this can lead to significant memory spikes and, if the body is empty but a Content-Type is declared, the framework throws the MissingRequestContent error before any application logic runs.
While the ContentNegotiation plugin maps media types to converters (e.g., JSON via kotlinx.serialization), it does not expose a streaming API for large arrays, forcing developers to manually use call.receiveStream and incremental parsing. The trade‑off between simplicity and memory efficiency has not yet been resolved in the Ktor roadmap.
Given the documented behavior, what criteria should determine when Ktor switches from buffering to streaming for incoming requests? How can developers expose a configurable threshold for automatic streaming without breaking existing code that relies on call.receive? Should the framework provide a dedicated plugin or configuration option to enable streaming for specific content types or request sizes?