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

Function parseHttpOriginHeader

scripts/bind-host.mjs:71–93  ·  view source on GitHub ↗
(rawOrigin)

Source from the content-addressed store, hash-verified

69 * @returns {{ host: string, hostname: string } | null}
70 */
71export function parseHttpOriginHeader(rawOrigin) {
72 if (typeof rawOrigin !== "string") return null;
73 const trimmed = rawOrigin.trim();
74 if (!trimmed || trimmed === "null") return null;
75 try {
76 const parsed = new URL(trimmed);
77 if (
78 (parsed.protocol !== "http:" && parsed.protocol !== "https:") ||
79 parsed.username ||
80 parsed.password
81 ) {
82 return null;
83 }
84 const hostname = parsed.hostname.replace(/^\[|\]$/g, "").toLowerCase();
85 if (!hostname) return null;
86 return {
87 host: parsed.host.toLowerCase(),
88 hostname,
89 };
90 } catch {
91 return null;
92 }
93}
94
95/**
96 * Whether an unbracketed lowercase hostname refers to loopback (`127.0.0.0/8`,

Callers 3

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

Calls

no outgoing calls

Tested by

no test coverage detected