mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 11:37:38 +00:00
refactor(gateway): share host header parsing
This commit is contained in:
@@ -1,26 +1,7 @@
|
||||
import { isLoopbackHost } from "./net.js";
|
||||
import { isLoopbackHost, normalizeHostHeader, resolveHostName } from "./net.js";
|
||||
|
||||
type OriginCheckResult = { ok: true } | { ok: false; reason: string };
|
||||
|
||||
function normalizeHostHeader(hostHeader?: string): string {
|
||||
return (hostHeader ?? "").trim().toLowerCase();
|
||||
}
|
||||
|
||||
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 ?? "";
|
||||
}
|
||||
|
||||
function parseOrigin(
|
||||
originRaw?: string,
|
||||
): { origin: string; host: string; hostname: string } | null {
|
||||
|
||||
Reference in New Issue
Block a user