openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
28 lines (27 loc) • 1.1 kB
JavaScript
//#region src/infra/fetch-headers.ts
function isHeadersLike(e) {
if (typeof Headers !== "undefined" && e instanceof Headers) return true;
const t = e;
return typeof t.entries === "function" && typeof t.get === "function" && typeof t[Symbol.iterator] === "function";
}
/** Normalizes HeadersInit records so fetch receives only string-keyed header properties. */
function normalizeHeadersInitForFetch(e) {
if (!e || typeof e !== "object" || Array.isArray(e) || isHeadersLike(e)) return e;
if (Object.getOwnPropertySymbols(e).length === 0) return e;
const t = Object.create(null);
const n = e;
for (const e of Object.getOwnPropertyNames(n)) t[e] = String(n[e]);
return t;
}
/** Normalizes request init headers without cloning the init object when no change is needed. */
function normalizeRequestInitHeadersForFetch(e) {
if (!e?.headers) return e;
const t = normalizeHeadersInitForFetch(e.headers);
if (t === e.headers) return e;
return {
...e,
headers: t
};
}
//#endregion
export { normalizeHeadersInitForFetch as n, normalizeRequestInitHeadersForFetch as r, isHeadersLike as t };