refactor(gateway): share host header parsing

This commit is contained in:
Peter Steinberger
2026-02-15 16:15:53 +00:00
parent 933a9945ae
commit 1843bcf1db
5 changed files with 24 additions and 56 deletions

View File

@@ -25,6 +25,25 @@ export function pickPrimaryLanIPv4(): string | undefined {
return undefined;
}
export function normalizeHostHeader(hostHeader?: string): string {
return (hostHeader ?? "").trim().toLowerCase();
}
export function resolveHostName(hostHeader?: string): string {
const host = normalizeHostHeader(hostHeader);
if (!host) {
return "";
}
if (host.startsWith("[")) {
const end = host.indexOf("]");
if (end !== -1) {
return host.slice(1, end);
}
}
const [name] = host.split(":");
return name ?? "";
}
export function isLoopbackAddress(ip: string | undefined): boolean {
if (!ip) {
return false;