namespace OpenNest.Data; /// Base-address validation shared by the nest server's HTTP clients. internal static class ServerUrl { /// /// The key that binds saved nests and library links to a server: the address trimmed, /// without trailing slashes. Two settings that differ only that way name the same server. /// public static string Key(string? url) => (url ?? "").Trim().TrimEnd('/'); /// /// Returns the absolute http(s) base address with exactly one trailing slash, so /// relative combines replace no path segment. Throws for any other address. /// public static Uri ParseBase(string? baseUrl, string paramName) { var url = (baseUrl ?? "").Trim().TrimEnd('/'); if (!Uri.TryCreate(url, UriKind.Absolute, out var baseUri) || (baseUri.Scheme != Uri.UriSchemeHttp && baseUri.Scheme != Uri.UriSchemeHttps)) { throw new ArgumentException($"Invalid nest server URL: '{baseUrl}'", paramName); } return new Uri(baseUri.AbsoluteUri.TrimEnd('/') + "/"); } }