Beispiel #1
0
        private (ActionInfo ai, HttpRoutInfo hri, string rawPath) GetActionInfo()
        {
            var rawPath = Helper.FormatPath(_context.Request.Path.Value);

            if (!string.IsNullOrEmpty(_rootPath))
            {
                var startS = $"{_rootPath}/".TrimStart('/');
                if (!rawPath.StartsWith(startS))
                {
                    throw new HttpNotMatchedException($"Request url:'{_context.Request.Path.Value}' is start with '{startS}'");
                }
                rawPath = rawPath.Substring(startS.Length);
            }

            foreach (var contract in _contracts)
            {
                foreach (var contractMethod in contract.Methods)
                {
                    HttpRoutInfo?hri = contractMethod.Route.MatchPath(rawPath, _context.Request.Method);
                    if (hri != null)
                    {
                        return(contractMethod.MethodInfo.ToActionInfo(), hri, rawPath);
                    }
                }
            }

            throw new HttpNotMatchedException($"Request url:'{_context.Request.Path.Value}' is not matched.");
        }
Beispiel #2
0
        private ActionInfo GetActionInfo()
        {
            var rawPath = Helper.FormatPath(_context.Request.Path.Value);

            if (!string.IsNullOrEmpty(_rootPath))
            {
                var startS = $"{_rootPath}/".TrimStart('/');
                if (!rawPath.StartsWith(startS))
                {
                    throw new HttpNotMatchedException($"Request url:'{_context.Request.Path.Value}' is start with '{startS}'");
                }
                rawPath = rawPath.Substring(startS.Length);
            }

            foreach (var contract in _contracts)
            {
                foreach (var contractMethod in contract.ContractInfo.Methods)
                {
                    if (rawPath == contractMethod.HttpRoutInfo.ToString())
                    {
                        return(contractMethod.MethodInfo.ToActionInfo());
                    }
                }
            }

            throw new HttpNotMatchedException($"Request url:'{_context.Request.Path.Value}' is not matched.");
        }