internal MatchResults MatchWith(Method?method, Uri?uri) { if (_method.Equals(method)) { if (uri == null || !uri.IsAbsoluteUri || uri.Scheme != "http" && uri.Scheme != "https") { throw new ArgumentException( "In order to match on Uri, it has to be an absolute uri for http or https scheme", nameof(uri)); } var path = uri.AbsolutePath; var pathCurrentIndex = 0; var totalSegments = _matchable.TotalSegments; var running = new RunningMatchSegments(totalSegments); for (var idx = 0; idx < totalSegments; ++idx) { var segment = _matchable.PathSegment(idx); if (segment.IsPathParameter) { running.KeepParameterSegment(pathCurrentIndex); pathCurrentIndex = IndexOfNextSegmentStart(pathCurrentIndex, path); } else { var indexOfSegment = path.IndexOf(segment.Value, pathCurrentIndex, StringComparison.InvariantCulture); if (indexOfSegment == -1 || (pathCurrentIndex == 0 && indexOfSegment != 0)) { return(UnmatchedResults); } var lastIndex = segment.LastIndexOf(indexOfSegment); running.KeepPathSegment(indexOfSegment, lastIndex); pathCurrentIndex = lastIndex; } } int nextPathSegmentIndex = IndexOfNextSegmentStart(pathCurrentIndex, path); if (nextPathSegmentIndex != path.Length) { if (nextPathSegmentIndex < path.Length - 1) { return(UnmatchedResults); } } var matchResults = new MatchResults(this, running, ParameterNames, path); return(matchResults); } return(UnmatchedResults); }
internal MatchResults MatchWith(Method method, Uri uri) { if (_method.Equals(method)) { var path = uri.AbsolutePath; var pathCurrentIndex = 0; var totalSegments = _matchable.TotalSegments; var running = new RunningMatchSegments(totalSegments); for (var idx = 0; idx < totalSegments; ++idx) { var segment = _matchable.PathSegment(idx); if (segment.IsPathParameter) { running.KeepParameterSegment(pathCurrentIndex); pathCurrentIndex = IndexOfNextSegmentStart(pathCurrentIndex, path); } else { var indexOfSegment = path.IndexOf(segment.Value, pathCurrentIndex); if (indexOfSegment == -1 || (pathCurrentIndex == 0 && indexOfSegment != 0)) { return(UnmatchedResults); } var lastIndex = segment.LastIndexOf(indexOfSegment); running.KeepPathSegment(indexOfSegment, lastIndex); pathCurrentIndex = lastIndex; } } int nextPathSegmentIndex = IndexOfNextSegmentStart(pathCurrentIndex, path); if (nextPathSegmentIndex != path.Length) { if (_disallowPathParametersWithSlash || nextPathSegmentIndex < path.Length - 1) { return(UnmatchedResults); } } var matchResults = new MatchResults(this, running, ParameterNames, path, _disallowPathParametersWithSlash); return(matchResults); } return(UnmatchedResults); }