David Glasser
08/23/2019, 9:53 PMval contentLength = call.request.header(HttpHeaders.ContentLength)?.toInt()
// Before reading the body, check to see if they provided a content-length that is too large. (Note that
// they could be using Transfer-Encoding:chunked and have no content-length.)
if (contentLength != null && contentLength > config.maxContentLength) {
throw RequestTooLargeException()
}
// Read the body into a "byte packet": a series of pool-allocated byte buffers. Note that we have
// to explicit close (directly or via the inputStream) to recycle the buffers back into the pool.
val body = call.receiveChannel().readRemaining(config.maxContentLength.toLong() + 1)
if (body.remaining > config.maxContentLength) {
body.close()
throw RequestTooLargeException()
}
// Make an InputStream from the ByteReadPacket. Because we've already read all the bytes,
// operations on this InputStream do not block.
body.inputStream().use { rawStream ->
but maybe there's an easier way