/// <summary> /// 从请求中解析出路由值 /// </summary> /// <param name="request">请求数据</param> /// <returns>路由值</returns> public IReadOnlyDictionary <string, string> GetRouteValues(RouteRequestData request) { if (Scheme != null && stringComparer.Equals(Scheme, request.Scheme) == false) { return(null); } var routeValues = new Dictionary <string, string>(stringComparer); if (HostTemplate != null) { var values = HostTemplate.GetRouteValues(request.Host); if (values == null) { return(null); } foreach (var pair in values) { routeValues.Add(pair.key, pair.value); } } { var values = PathTemplate.GetRouteValues(request.Path); if (values == null) { return(null); } foreach (var pair in values) { routeValues.Add(pair.Key, pair.Value); } } if (QueryStringTemplate != null) { var values = QueryStringTemplate.GetRouteValues(request.Path); if (values == null) { return(null); } foreach (var pair in values) { routeValues.Add(pair.Key, pair.Value); } } return(routeValues); }
/// <summary> /// 产生路由值 /// </summary> /// <param name="requestData"></param> /// <returns></returns> public IReadOnlyDictionary <string, string> Match(RouteRequestData requestData) { if (Upstreams.Any() == false) { return(new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase)); } foreach (var item in Upstreams) { var values = item.GetRouteValues(requestData); if (values != null) { return(values); } } return(null); }