/// <summary> /// Passes incoming requests to the correct route /// </summary> public async Task <WebResponse> Route(WebRequest request) { _logger.Info($"Request: {request}"); if (request.Path == null) { _logger.Error($"Request path not set, please check sever request mapping implementation"); return(await WebResponse.InternalServerError()); } if (_routes.ContainsKey(request.Path)) { IWebRoute route = _routes[request.Path]; Task <WebResponse> responseTask = null; switch (request.Method) { case WebRequestMethod.Get: responseTask = route.Get(request); break; case WebRequestMethod.Post: responseTask = route.Post(request); break; case WebRequestMethod.Put: responseTask = route.Put(request); break; case WebRequestMethod.Delete: responseTask = route.Delete(request); break; } if (responseTask == null) { _logger.Info($"Request method: {request.Method} not supported for requested path: {request.Path}"); return(await WebResponse.InternalServerError()); } WebResponse response = await responseTask; response.RouteFound = true; if (!string.IsNullOrEmpty(_setting.WebSetting.ServerHeader)) { response.Header.Add("Server", _setting.WebSetting.ServerHeader); } return(response); } return(await WebResponse.NotFound()); }
public override HttpControllerDescriptor SelectController(HttpRequestMessage request) { IHttpRouteData routeDate = request.GetRouteData(); IWebRoute ewroute = routeDate.Route as IWebRoute; if (ewroute == null) { return(base.SelectController(request)); } return(controllers.GetOrAdd( ewroute.ControllerName, key => new HttpControllerDescriptor(configuration, key, ewroute.ControllerType))); }
public void AddRoute(IWebRoute route) { this._router.AddRoute(route); }
/// <summary> /// Adds a handler for a specific route. /// </summary> public void AddRoute(IWebRoute route) { _routes.Add(route.Route, route); }