Future receive(Request req)

The mechanism for delivering a Request to this controller for processing.

This method is the entry point of a Request into this RequestController. By default, it invokes this controller's processRequest method and, if that method determines processing should continue to the nextController and a nextController exists, the request will be delivered to nextController.

An RequestSink invokes this method on its initial controller in its processRequest method.

Some RequestControllers may override this method if they do not wish to use simple chaining. For example, the Router class overrides this method to deliver the Request to the appropriate RouteController. If overriding this method, it is important that you always invoke subsequent controller's with receive and not processRequest. You must also ensure that CORS requests are handled properly, as this method does the heavy-lifting for handling CORS requests.

Source

Future receive(Request req) async {
  if (req.isPreflightRequest) {
    return _handlePreflightRequest(req);
  }

  var result;
  try {
    result = await processRequest(req);
    if (result is Response) {
      await _sendResponse(req, result, includeCORSHeaders: true);
      logger.info(req.toDebugString());
      return null;
    }
  } catch (any, stacktrace) {
    var shouldRethrow = await handleError(req, any, stacktrace);
    if (letUncaughtExceptionsEscape && shouldRethrow) {
      rethrow;
    }

    return null;
  }

  return nextController?.receive(result);
}