runRoute function

void runRoute(
  1. HttpRequest req,
  2. RouteMatch match
)

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

Implementation

void runRoute(HttpRequest req, RouteMatch match) {
  try {
    RouteData route = match.route;
    Map<String, dynamic>? params = match.params;

    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? contentType = req.headers.contentType;
    RequestBody? now = contentType == null
        ? RequestBody.empty()
        : HttpBody.readNow(req, contentType);
    if (now != null) {
      _run(req, _doxRequest(req, route, params, now, contentType));
    } else {
      HttpBody.read(req, contentType).then(
        (RequestBody body) {
          try {
            _run(req, _doxRequest(req, route, params, body, contentType));
          } catch (error, stackTrace) {
            httpErrorHandler(req, error, stackTrace);
          }
        },
        onError: (Object error, StackTrace stackTrace) {
          httpErrorHandler(req, error, stackTrace);
        },
      );
    }

    /// form data do not support isolate or multithread
  } catch (error, stackTrace) {
    httpErrorHandler(req, error, stackTrace);
  }
}