cookie-pusher
Version:
Cookie-aware HTTP client based on axios and tough-cookie
12 lines (11 loc) • 506 B
JavaScript
export const parseRawHeadersIntoObject = (rawHeaders) => rawHeaders
.split(`\n`)
.filter((line) => !/^(?:\s*$|[A-Z]+\ )/.test(line))
.map((line) => {
const colonIndex = line.indexOf(`:`);
const key = line.substring(0, colonIndex).trim();
const value = line.substring(colonIndex + 1).trim();
return { key, value };
})
.reduce((headers, header) => (Object.assign(Object.assign({}, headers), { [header.key]: header.value })), {});
export default { parseRawHeadersIntoObject };