@lobehub/chat
Version:
Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.
28 lines (27 loc) • 765 B
text/typescript
/**
* 将 HeadersInit 转换为 Record<string, string>
* @param headersInit - Headers 初始化对象
* @returns 转换后的记录对象
*/
// eslint-disable-next-line no-undef
export const headersToRecord = (headersInit?: HeadersInit): Record<string, string> => {
const record: Record<string, string> = {};
if (!headersInit) {
return record;
}
if (headersInit instanceof Headers) {
headersInit.forEach((value, key) => {
record[key] = value;
});
} else if (Array.isArray(headersInit)) {
headersInit.forEach(([key, value]) => {
record[key] = value;
});
} else {
Object.assign(record, headersInit);
}
delete record['host'];
delete record['connection'];
delete record['content-length'];
return record;
};