Crunchy-Downloader/Utils/Parser/Utils/UrlUtils.cs
2024-05-04 17:35:32 +02:00

23 lines
No EOL
896 B
C#

using System;
namespace CRD.Utils.Parser.Utils;
public class UrlUtils{
public static string ResolveUrl(string baseUrl, string relativeUrl){
// Return early if the relative URL is actually an absolute URL
if (Uri.IsWellFormedUriString(relativeUrl, UriKind.Absolute))
return relativeUrl;
// Handle the case where baseUrl is not specified or invalid
Uri baseUri;
if (string.IsNullOrEmpty(baseUrl) || !Uri.TryCreate(baseUrl, UriKind.Absolute, out baseUri)){
// Assuming you want to use a default base if none is provided
// For example, you could default to "http://example.com"
// This part is up to how you want to handle such cases
baseUri = new Uri("http://example.com");
}
Uri resolvedUri = new Uri(baseUri, relativeUrl);
return resolvedUri.ToString();
}
}