scoop:scoop.http.server:0.1.0
src/body/aggregate.scoop
Selected production source · src/body/aggregate.scoop
1
package scoop.http.server3
import scoop.asyncio.AsyncByteSource4
import scoop.bytes.ByteArrayBuilder5
import scoop.platform.memory.NativeByteBuffer7
internal suspend fun aggregateRequestBody(source: AsyncByteSource, maxBytes: Long): Array<Byte> =8
NativeByteBuffer.allocate(8192L).use suspend { buffer ->9
val result = ByteArrayBuilder()10
var total = 0L11
while (true) {12
buffer.clear()13
val remaining = maxBytes - total14
val count = source.readInto(buffer, if (remaining < 8192L) remaining + 1L else 8192L)15
if (count == 0L) break16
if (count > remaining) reject(413U, "request body exceeds aggregation limit")17
result.append(buffer.readBytes(count))18
total += count19
}20
result.toByteArray()21
}