Skip to content

Instantly share code, notes, and snippets.

@aristidb
Created December 3, 2008 22:07
Show Gist options
  • Save aristidb/31723 to your computer and use it in GitHub Desktop.
Save aristidb/31723 to your computer and use it in GitHub Desktop.
function headers(str) {
var lst = str.split("\n");
var hdr = {};
hdr.__proto__ = null;
lst.forEach(function (x) {
if (!x.length)
return;
[ name, value ] = x.split(/\s*:\s*/, 2);
if (!hdr[name])
hdr[name] = value;
else if (value)
hdr[name] += ', ' + value;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment