content_length_validator 1.0.0+1 content_length_validator: ^1.0.0+1 copied to clipboard
Middleware for Shelf and Dart Frog to block too large requests.
example/content_length_validator_example.dart
// ignore_for_file: avoid_print
import 'package:content_length_validator/content_length_validator.dart';
import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart' as shelf_io;
void main() async {
final handler = const Pipeline()
.addMiddleware(maxContentLengthValidator())
.addMiddleware(logRequests())
.addHandler(_echoRequest);
final server = await shelf_io.serve(handler, 'localhost', 8080);
// Enable content compression
server.autoCompress = true;
print('Serving at http://${server.address.host}:${server.port}');
}
Response _echoRequest(Request request) =>
Response.ok('Request for "${request.url}"');