Skip to content

Instantly share code, notes, and snippets.

@fsvehla
Created February 29, 2012 15:43
Show Gist options
  • Save fsvehla/1941819 to your computer and use it in GitHub Desktop.
Save fsvehla/1941819 to your computer and use it in GitHub Desktop.
var parseResponseCookies = function (response) {
var Cookie = function (cookieString) {
var fields = cookieString.split(/; ?/).map(function (item) {
return item.split('=');
});
var metadata = fields.reduce(function (prev, curr) {
prev[curr[0]] = curr[1];
return prev;
}, {});
this.name = fields[0][0];
this.value = fields[0][1];
this.path = metadata['path'];
this.domain = metadata['domain'];
this.isDeleted = (this.value === '');
return this;
};
return response.headers['set-cookie'].reduce(function (prev, curr) {
var cookie = new Cookie(curr);
prev[cookie.name] = cookie;
return prev;
}, {});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment