addResponseModifier method

void addResponseModifier(
  1. void modifier(
    1. Response response
    )
)

Allows a Controller to modify the response eventually created for this request, without creating that response itself.

Executes modifier prior to sending the HTTP response for this request. Modifiers are executed in the order they were added and may contain modifiers from other Controllers. Modifiers are executed prior to any data encoded or is written to the network socket.

This is valuable for middleware that wants to include some information in the response, but some other controller later in the channel will create the response. modifier will run prior to

Usage:

    Future<RequestOrResponse> handle(Request request) async {
      request.addResponseModifier((r) {
        r.headers["x-rate-limit-remaining"] = 200;
      });
      return request;
    }

Implementation

void addResponseModifier(void Function(Response response) modifier) {
  _responseModifiers ??= [];
  _responseModifiers!.add(modifier);
}