MCPcopy Create free account
hub / github.com/OpenHands/OpenHands / parseHttpHostHeader

Function parseHttpHostHeader

scripts/bind-host.mjs:37–62  ·  view source on GitHub ↗
(rawHost)

Source from the content-addressed store, hash-verified

35 * @returns {{ host: string, hostname: string, port: string } | null}
36 */
37export function parseHttpHostHeader(rawHost) {
38 if (typeof rawHost !== "string") return null;
39 const trimmed = rawHost.trim();
40 if (!trimmed || !HOST_AUTHORITY_RE.test(trimmed)) return null;
41 try {
42 const parsed = new URL(`http://${trimmed}`);
43 if (
44 parsed.username ||
45 parsed.password ||
46 parsed.pathname !== "/" ||
47 parsed.search ||
48 parsed.hash
49 ) {
50 return null;
51 }
52 const hostname = parsed.hostname.replace(/^\[|\]$/g, "").toLowerCase();
53 if (!hostname) return null;
54 return {
55 host: parsed.host.toLowerCase(),
56 hostname,
57 port: parsed.port,
58 };
59 } catch {
60 return null;
61 }
62}
63
64/**
65 * Parse an HTTP `Origin` header into a lowercase authority and unbracketed

Callers 3

bind-host.test.tsFile · 0.90
isCrossOriginHttpRequestFunction · 0.85
isForeignLoopbackRequestFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected