mirror of
https://github.com/hesprs/obsidian-webdav-sync.git
synced 2026-07-22 14:30:27 +00:00
* feat(settings): Add custom headers option * add customHeaders to fs/webdav/api * eslint to oxlint
18 lines
519 B
TypeScript
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;
|
|
}
|