addResponseModifier method

void addResponseModifier (void modifier(Response response))

Allows a RequestController 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 RequestControllers. 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


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


void addResponseModifier(void modifier(Response response)) {
  _responseModifiers ??= [];