httpRequestHandler function
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);
/// no Content-Type means no body to read. then the request is
/// made at once, with no Future in between.
/// read the header once and pass it on.
ContentType? contentType = req.headers.contentType;
if (contentType == null) {
_run(req, _doxRequest(req, route, RequestBody.empty(), null));
} else {
HttpBody.read(req, contentType).then(
(RequestBody body) {
try {
_run(req, _doxRequest(req, route, 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);
}
}