httpRequestHandler function

void httpRequestHandler(
  1. HttpRequest req
)

this is a class which get matched routes and pass http request to route middleware and controllers and response from controllers is passed to httpResponseHandler

Implementation

void httpRequestHandler(HttpRequest req) {
  try {
    /// raw handlers like Socket.IO. empty map when nothing is mounted.
    Map<String, RawRequestHandler> mounts = Route().mounts;
    if (mounts.isNotEmpty && _mounted(req, mounts)) return;

    /// a path with no route at all gets 404 for any `_method`, so its
    /// body is not read
    if (req.method == 'POST' &&
        MethodOverride.enabledIn(Dox().config.globalMiddleware) &&
        httpPathHasRoute(req)) {
      _withMethodOverride(req);
      return;
    }

    RouteMatch? match = httpRouteHandler(req);
    if (match != null) runRoute(req, match);
  } catch (error, stackTrace) {
    httpErrorHandler(req, error, stackTrace);
  }
}