mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-11-05 21:55:47 -05:00
The drawing library client needs the same base-address rule as the nest repository. Extract it into one internal helper so both clients accept and reject exactly the same addresses. Behavior is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
22 lines
828 B
C#
22 lines
828 B
C#
namespace OpenNest.Data;
|
|
|
|
/// <summary>Base-address validation shared by the nest server's HTTP clients.</summary>
|
|
internal static class ServerUrl
|
|
{
|
|
/// <summary>
|
|
/// Returns the absolute http(s) base address with exactly one trailing slash, so
|
|
/// relative combines replace no path segment. Throws for any other address.
|
|
/// </summary>
|
|
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('/') + "/");
|
|
}
|
|
}
|