Example #1
0
 /// <summary>
 /// 创建 RouteRequestData 对象
 /// </summary>
 /// <param name="request"></param>
 public RouteRequestData(HttpRequestMessage request)
 {
     Path        = PathSegments.Create(request.RequestUri.AbsolutePath);
     Host        = HostSegments.Create(request.RequestUri.Host);
     Scheme      = request.RequestUri.Scheme;
     QueryString = new ReadOnlyCollection <(string name, string value)>(ParseQueryString(request.RequestUri.Query).ToArray());
 }
Example #2
0
        public IEnumerable <(string key, string value)> GetRouteValues(HostSegments host)
        {
            var result = new List <(string key, string value)>(segments.Length);


            bool TryMatch(int length)
            {
                if (host.Count < length)
                {
                    return(false);
                }


                for (var i = 1; i < length + 1; i++)
                {
                    var item     = segments[segments.Length - i];
                    var hostItem = host[host.Count - i];
                    if (item.Type == SegmentType.Dynamic)
                    {
                        result.Add((item.Value, hostItem));
                    }

                    else if (item.Type == SegmentType.Static && stringComparer.Equals(item.Value, hostItem) == false)
                    {
                        return(false);
                    }
                }

                return(true);
            }

            if (infinityKey != null)
            {
                var length = segments.Length - 1;

                if (TryMatch(length) == false)
                {
                    return(null);
                }


                result.Add((infinityKey, string.Join('.', host.Take(host.Count - length))));
            }
            else
            {
                if (TryMatch(segments.Length) == false)
                {
                    return(null);
                }
            }

            return(result);
        }