UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

36 lines (35 loc) • 1.17 kB
import { l as normalizeOptionalString, o as normalizeLowercaseStringOrEmpty } from "./string-coerce-CCIiB4H7.mjs"; //#region src/gateway/http-header-value.ts function firstHeaderValue(e) { return Array.isArray(e) ? e[0] : e; } function getHeader(e, t) { return firstHeaderValue(e.headers[normalizeLowercaseStringOrEmpty(t)]); } function getBearerToken(e) { const t = normalizeOptionalString(getHeader(e, "authorization")) ?? ""; if (!normalizeLowercaseStringOrEmpty(t).startsWith("bearer ")) return; return normalizeOptionalString(t.slice(7)); } /** Split only outside quotes; entity-tags keep backslashes literal instead of escaping quotes. */ function splitHttpHeaderValue(e, t, n) { const r = []; let i = 0; let a = false; let o = false; for (let s = 0; s < e.length; s += 1) { const c = e[s]; if (o) o = false; else if (a && n === "quoted-string" && c === "\\") o = true; else if (c === "\"") a = !a; else if (!a && c === t) { r.push(e.slice(i, s)); i = s + 1; } } if (a || o) return null; r.push(e.slice(i)); return r; } //#endregion export { splitHttpHeaderValue as i, getBearerToken as n, getHeader as r, firstHeaderValue as t };