runRoute function

void runRoute(
  1. HttpRequest req,
  2. RouteMatch match, {
  3. RequestBody? body,
})

read the body, then run the middleware and controller of match

body is a body that was read already (the _method check reads it first). Then it is not read again.

Implementation

void runRoute(HttpRequest req, RouteMatch match, {RequestBody? body}) {
  RouteData route = match.route;
  Map<String, dynamic>? params = match.params;
  ContentType? contentType;
  try {
    httpCorsHandler(route.corsEnabled, req);

    /// no Content-Type means no body to read. a body the native server
    /// already holds is read at once too. then the request is made with
    /// no Future in between. read the header once and pass it on.
    contentType = HttpBody.contentTypeOf(req.headers);
    RequestBody? now =
        body ??
        (contentType == null
            ? RequestBody.empty()
            : HttpBody.readNow(req, contentType));
    if (now != null) {
      _run(req, _doxRequest(req, route, params, now, contentType));
    } else {
      _readThenRun(req, route, params, contentType!);
    }

    /// form data do not support isolate or multithread
  } catch (error, stackTrace) {
    _failed(req, route, params, contentType, error, stackTrace);
  }
}