Created
February 29, 2012 15:43
-
-
Save fsvehla/1941819 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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