Beispiel #1
0
        public new static HttpLink From(string value, bool strict = true)
        {
            var schemeParts = value.Split(new[] { Uri.SchemeDelimiter }, StringSplitOptions.None);

            if (schemeParts.Length == 2)
            {
                var pathSeparatorIndex = schemeParts[1].IndexOf('/');

                if (pathSeparatorIndex == -1 || pathSeparatorIndex == schemeParts[1].Length - 1)
                {
                    var host = HttpHost.From(value, strict: false);

                    if (host != null)
                    {
                        return(new HttpLink(host, HttpResource.Root));
                    }
                }
                else
                {
                    var hostText     = schemeParts[0] + Uri.SchemeDelimiter + schemeParts[1].Substring(0, pathSeparatorIndex);
                    var resourceText = schemeParts[1].Substring(pathSeparatorIndex + 1);

                    var host = HttpHost.From(hostText, strict: false);

                    if (host != null)
                    {
                        var resource = HttpResource.From(resourceText, strict: false);

                        if (resource != null)
                        {
                            return(new HttpLink(host, resource));
                        }
                    }
                }
            }

            ExpectNot(strict, "Failed to parse HTTP link: " + value);

            return(null);
        }
Beispiel #2
0
        public static HttpLink From(string host, string resource, bool strict = true)
        {
            var parsedHost = HttpHost.From(host, strict);

            return(parsedHost == null ? null : From(parsedHost, resource, strict));
        }