1. @override
Future receive(Request req)

Delivers req to this instance to be processed.

This method is the entry point of a Request into this RequestController. By default, it invokes this controller's processRequest method within a try-catch block that guarantees an HTTP response will be sent for Request.

Source

@override
Future receive(Request req) async {
  RequestController next;
  try {
    var requestURISegmentIterator = req.innerRequest.uri.pathSegments.iterator;
    if (_basePathSegments.length > 0) {
      for (var i = 0; i < _basePathSegments.length; i++) {
        requestURISegmentIterator.moveNext();
        if (_basePathSegments[i] != requestURISegmentIterator.current) {
          await _unhandledRequestController(req);
          return null;
        }
      }
    }

    var remainingSegments = <String>[];
    while (requestURISegmentIterator.moveNext()) {
      remainingSegments.add(requestURISegmentIterator.current);
    }
    if (remainingSegments.isEmpty) {
      remainingSegments = [""];
    }

    var node = _rootRouteNode.nodeForPathSegments(remainingSegments);
    if (node?.specification == null) {
      await _unhandledRequestController(req);
      return null;
    }

    var requestPath = new HTTPRequestPath(node.specification, remainingSegments);
    req.path = requestPath;
    next = node.controller;
  } catch (any, stack) {
    return handleError(req, any, stack);
  }

  return next?.receive(req);
}