Ensures that your application is not vulnerable to large payload attacks. Inspired by https://github.com/ericmdantas/express-content-length-validator
dart pub add content_length_validator
import 'package:content_length_validator/content_length_validator.dart';
var handler = const Pipeline()
.addMiddleware(
maxContentLengthValidator(
maxContentLength: YOUR_CONTENT_LENGTH,
),
)
.addMiddleware(logRequests())
.addHandler(_echoRequest);
import 'package:content_length_validator/content_length_validator.dart';
Handler maxContentLengthValidator(Handler handler) {
return handler.use(fromShelfMiddleware(maxContentLengthValidator(maxContentLength: YOUR_CONTENT_LENGTH,)));
}
.addMiddleware(
maxContentLengthValidator(
maxContentLength: YOUR_CONTENT_LENGTH,
errorResponse: Response(
413,
body: 'Your body is too long',
),
),
),
),