Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
parse-headers
const headers = `
Date: Sun, 17 Aug 2014 16:24:52 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Set-Cookie: Foo2
set-Cookie: bar
set-cookie: bong
`;
const s = headers.trim().split(/\s*\n\s*/g).map((v) => {
const [header, value] = v.split(/:\s*/, 2);
return [header.toLowerCase(), value]
})
console.log(s);
const a = new URLSearchParams(s)
console.log(a.getAll('set-cookie'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.