toMiddleware method

  1. @override
Middleware toMiddleware()
override

Builds the shelf middleware this value configures.

Implementation

@override
Middleware toMiddleware() {
  return (Handler inner) {
    return (Request request) async {
      final inbound = request.headers[header];
      final id = _acceptableId(inbound, maxLength)
          ? inbound!
          : (generate ?? _randomId)();
      final response = await inner(
        request.change(context: {requestIdContextKey: id}),
      );
      return response.change(headers: {header: id});
    };
  };
}