httpRouteHandler function
Implementation
RouteData? httpRouteHandler(HttpRequest req) {
RouteData? route = _getMatchRoute(
req.uri.path,
req.method,
req.headers.value(HttpHeaders.hostHeader),
);
if (route == null) {
/// answer preflight OPTIONS with 204 and cors headers.
/// use cors setting of the route the browser is asking about.
if (req.method == HttpRequestMethod.OPTIONS.name) {
RouteData? target = _getMatchRoute(
req.uri.path,
req.headers.value('access-control-request-method') ?? '',
req.headers.value(HttpHeaders.hostHeader),
);
httpCorsHandler(target?.corsEnabled, req);
req.response.statusCode = HttpStatus.noContent;
responseDataHandler(null, req);
} else {
req.response.statusCode = HttpStatus.notFound;
responseDataHandler('${req.method} ${req.uri.path} not found', req);
}
}
return route;
}