Skip to content

Commit

Permalink
Also add cookie to the user defined cookie jar (mikeal's suggestion)
Browse files Browse the repository at this point in the history
  • Loading branch information
alessioalex committed Nov 13, 2011
1 parent 366831b commit 88488cf
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,13 +418,16 @@ Request.prototype.request = function () {
response.body = JSON.parse(response.body)
} catch (e) {}
}
if (response.statusCode == 200) {
// only add cookies if no custom jar is defined (by the user)
if (response.headers['set-cookie'] && !self.jar) {
response.headers['set-cookie'].forEach(function(cookie) {
if (response.statusCode == 200 && response.headers['set-cookie']) {
response.headers['set-cookie'].forEach(function(cookie) {
if (self.jar) {
// custom defined jar
self.jar.add(new Cookie(cookie));
} else {
// add to the global cookie jar if user don't define his own
cookieJar.add(new Cookie(cookie));
});
}
}
});
}

self.callback(null, response, response.body)
Expand Down

0 comments on commit 88488cf

Please sign in to comment.