Created
July 26, 2020 20:42
-
-
Save tinovyatkin/02ce0b62a35a9cd9e587a55355c28e52 to your computer and use it in GitHub Desktop.
parse-headers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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