mirror of
https://github.com/DorkSquadRR/DorkNet.git
synced 2026-10-25 23:18:44 -07:00
feat: Enhance domain configuration to support hyphen subdomains and update related methods
This commit is contained in:
@@ -12,14 +12,22 @@ public sealed class DomainConfig
|
||||
{
|
||||
public string Apex { get; }
|
||||
public string Scheme { get; }
|
||||
public string HostStyle { get; }
|
||||
public bool UsesHyphenSubdomains => HostStyle == "hyphen";
|
||||
|
||||
public DomainConfig(string apex, string scheme = "https")
|
||||
public DomainConfig(string apex, string scheme = "https", string hostStyle = "dot")
|
||||
{
|
||||
Apex = apex;
|
||||
Scheme = NormalizeScheme(scheme);
|
||||
HostStyle = NormalizeHostStyle(hostStyle);
|
||||
}
|
||||
|
||||
public string Sub(string prefix)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(prefix)) return Apex;
|
||||
return UsesHyphenSubdomains ? $"{prefix}-{Apex}" : $"{prefix}.{Apex}";
|
||||
}
|
||||
|
||||
public string Sub(string prefix) => $"{prefix}.{Apex}";
|
||||
public string Url(string prefix, string path = "")
|
||||
{
|
||||
var host = string.IsNullOrEmpty(prefix) ? Apex : Sub(prefix);
|
||||
@@ -28,11 +36,18 @@ public sealed class DomainConfig
|
||||
}
|
||||
|
||||
public static bool MatchesSubdomain(string host, string prefix)
|
||||
=> host.StartsWith(prefix + ".", StringComparison.OrdinalIgnoreCase);
|
||||
=> host.StartsWith(prefix + ".", StringComparison.OrdinalIgnoreCase)
|
||||
|| host.StartsWith(prefix + "-", StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
private static string NormalizeScheme(string? value)
|
||||
{
|
||||
var scheme = string.IsNullOrWhiteSpace(value) ? "https" : value.Trim().TrimEnd(':', '/', '\\').ToLowerInvariant();
|
||||
return scheme is "http" or "https" ? scheme : "https";
|
||||
}
|
||||
|
||||
private static string NormalizeHostStyle(string? value)
|
||||
{
|
||||
var style = string.IsNullOrWhiteSpace(value) ? "dot" : value.Trim().ToLowerInvariant();
|
||||
return style is "hyphen" or "dash" or "flat" ? "hyphen" : "dot";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user