private HttpResponse RouteRequest() { var routes = this.Routes .Where(x => Regex.Match(Request.Url, x.UrlRegex).Success) .ToList(); if (!routes.Any()) { return(HttpResponseBuilder.NotFound()); } var route = routes.FirstOrDefault(x => x.Method == Request.Method); if (route == null) { return new HttpResponse() { StatusCode = ResponseStatusCode.MethodNotAllowed } } ; #region FIleSystemHandler // extract the path if there is one //var match = Regex.Match(request.Url, route.UrlRegex); //if (match.Groups.Count > 1) //{ // request.Path = match.Groups[1].Value; //} //else //{ // request.Path = request.Url; //} #endregion // trigger the route handler... try { return(route.Callable(Request)); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); return(HttpResponseBuilder.InternalServerError()); } }
private HttpResponse RouteRequest() { var routes = this.Routes .Where(x => Regex.Match(Request.Url, x.UrlRegex).Success) .ToList(); if (!routes.Any()) { return(HttpResponseBuilder.NotFound()); } var route = routes.FirstOrDefault(x => x.Method == Request.Method); if (route == null) { return new HttpResponse() { StatusCode = ResponseStatusCode.MethodNotAllowed } } ; // trigger the route handler... try { return(route.Callable(Request)); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); return(HttpResponseBuilder.InternalServerError()); } }