content_length_validator 1.2.1 copy "content_length_validator: ^1.2.1" to clipboard
content_length_validator: ^1.2.1 copied to clipboard

Middleware for Shelf and Dart Frog to block too large requests.

Dart Content Length Validator #

Ensures that your application is not vulnerable to large payload attacks. Inspired by https://github.com/ericmdantas/express-content-length-validator

Installing #

dart pub add content_length_validator

Usage #

As shelf middleware #

import 'package:content_length_validator/content_length_validator.dart';

  var handler = const Pipeline()
      .addMiddleware(
        maxContentLengthValidator(
          maxContentLength: YOUR_CONTENT_LENGTH,
        ),
      )
      .addMiddleware(logRequests())
      .addHandler(_echoRequest);

As dart_frog middleware #

import 'package:content_length_validator/content_length_validator.dart';

Handler maxContentLengthValidator(Handler handler) {
    return handler.use(fromShelfMiddleware(maxContentLengthValidator(maxContentLength: YOUR_CONTENT_LENGTH,)));
}

Defining custom error response #

.addMiddleware(
    maxContentLengthValidator(
      maxContentLength: YOUR_CONTENT_LENGTH,
      errorResponse: Response(
        413,
        body: 'Your body is too long',
        ),
      ),
    ),
  ),
6
likes
160
points
993
downloads

Publisher

verified publisherjxstxn.dev

Weekly Downloads

Middleware for Shelf and Dart Frog to block too large requests.

Homepage
Repository (GitHub)
View/report issues

Topics

#shelf #security #dart-frog #middleware #content-length

Documentation

API reference

License

Apache-2.0 (license)

Dependencies

shelf

More

Packages that depend on content_length_validator