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;

    RouteData? route = httpRouteHandler(req);
    if (route == null) return;

    httpCorsHandler(route.corsEnabled, req);

    if (WebSocketTransformer.isUpgradeRequest(req)) {
      httpWebSocketHandler(req, route);
      return;
    }

    /// no Content-Type means no body to read. then the request is
    /// made at once, with no Future in between.
    if (req.headers.contentType == null) {
      _run(req, _doxRequest(req, route, RequestBody.empty()));
    } else {
      HttpBody.read(req)
          .then((RequestBody body) {
            _run(req, _doxRequest(req, route, body));
          })
          .onError((Object? error, StackTrace stackTrace) {
            httpErrorHandler(req, error, stackTrace);
          });
    }

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