Beispiel #1
0
        public static Href From(string value, bool strict = true)
        {
            var href = HttpLink.From(value, strict: false) ?? HttpResource.From(value, strict: false) as Href;

            ExpectNot(strict && href == null, "Failed to parse href: " + value);

            return(href);
        }
Beispiel #2
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 #3
0
        public static HttpLink From(HttpHost host, string resource, bool strict = true)
        {
            var parsedResource = HttpResource.From(resource, strict);

            return(parsedResource == null ? null : new HttpLink(host, parsedResource));
        }