hesprs_obsidian-webdav-sync/src/utils/parse-headers.ts
brycepollack e2cdca9da0
feat(settings): Add custom headers option (#158)
* feat(settings): Add custom headers option

* add customHeaders to fs/webdav/api

* eslint to oxlint
2026-06-22 12:23:46 +08:00

18 lines
519 B
TypeScript

const HEADER_NAME = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
export default function parseHeaders(raw: string) {
const headers: Record<string, string> = {};
for (const line of raw.split(/\r?\n/)) {
const trimmed = line.trim();
if (trimmed === '') continue;
const colon = trimmed.indexOf(':');
if (colon === -1) return false;
const name = trimmed.slice(0, colon).trim();
const value = trimmed.slice(colon + 1).trim();
if (!HEADER_NAME.test(name)) return false;
headers[name] = value;
}
return headers;
}