readBytes static method
read the whole body, but stop with 413 once it passes max bytes.
Implementation
static Future<Uint8List> readBytes(HttpRequest request, int max) async {
_checkContentLength(request, max);
/// the native server already holds the whole body. no stream needed.
if (request is NativeRequest) {
if (request.body.length > max) throw PayloadTooLargeException();
return request.body;
}
BytesBuilder builder = BytesBuilder(copy: false);
await for (List<int> chunk in limit(request, max)) {
builder.add(chunk);
}
return builder.takeBytes();
}