Skip to content

Instantly share code, notes, and snippets.

@Alex-Werner
Created July 13, 2016 09:17
Show Gist options
  • Save Alex-Werner/d1641cb797a3cda0e6083c27522dc832 to your computer and use it in GitHub Desktop.
Save Alex-Werner/d1641cb797a3cda0e6083c27522dc832 to your computer and use it in GitHub Desktop.
function parseCookies(cookie) {
return cookie.split(';').reduce(
function(prev, curr) {
var m = / *([^=]+)=(.*)/.exec(curr);
var key = m[1];
var value = decodeURIComponent(m[2]);
prev[key] = value;
return prev;
},
{ }
);
}
function stringifyCookies(cookies) {
var list = [ ];
for (var key in cookies) {
list.push(key + '=' + encodeURIComponent(cookies[key]));
}
return list.join('; ');
}
var cookies = parseCookies(request.headers.cookie);
console.log(cookies['session']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment