Skip to content

Instantly share code, notes, and snippets.

@tinovyatkin
Created July 26, 2020 20:42
Show Gist options
  • Save tinovyatkin/02ce0b62a35a9cd9e587a55355c28e52 to your computer and use it in GitHub Desktop.
Save tinovyatkin/02ce0b62a35a9cd9e587a55355c28e52 to your computer and use it in GitHub Desktop.
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