layers library

Middleware that ships in the box: deadlines, request ids, access records.

Nothing is installed by default. An application adds what it wants:

import 'package:dust_server/layers.dart';

final app = Router()
  ..layer(const RequestTimeout(Duration(seconds: 30)))
  ..layer(const RequestId())
  ..layer(AccessLog(logger.info));

Everything here is also exported from package:dust_server/server.dart.

Classes

AccessLog
Reports every served request to onRecord.
AccessRecord
One served request, as the application should record it.
AllowedOrigins
Which origins a browser may call this server from.
Compression
Compresses responses a client said it can decompress.
Cors
Answers the cross-origin questions a browser asks before it will hand a response to JavaScript.
Extension<T extends Object>
Reads a value a fromExtractor layer already produced.
NormalizePath
Makes /todos and /todos/ mean the same thing.
RequestId
Gives every request an id, and echoes it back.
RequestTimeout
Gives every request below it a deadline.
SecurityHeaders
Adds the response headers a browser uses to lock a page down.

Enums

TrailingSlash
What to do about a trailing slash.

Constants

defaultCompressibleTypes → const Set<String>
Content types worth compressing.
requestIdContextKey → const String
The context key a request id travels under.

Functions

extensionKeyFor<T>() String
The context key a value extracted by fromExtractor travels under.
fromExtractor<T extends Object>(FromRequestParts<T> extractor) Middleware
Runs extractor as middleware, and passes its value on to the handler.
requestIdOf(Request request) String?
The id given to this request, or null when no RequestId layer ran.