Skip to content

Commit

Permalink
Fix cookie jar/headers.cookie collision. Closes #125.
Browse files Browse the repository at this point in the history
If both a cookie jar and headers.cookie are specified, include both in the request, separated by '; '. Also fixed uppercase header name: self.headers.Cookie => self.headers.cookie.
  • Loading branch information
papandreou committed Feb 8, 2012
1 parent a0ab977 commit c80800a
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,17 @@ Request.prototype.request = function () {
// fetch cookie from the global cookie jar
var cookies = cookieJar.get({ url: self.uri.href })
}
if (cookies) {
if (cookies && cookies.length) {
var cookieString = cookies.map(function (c) {
return c.name + "=" + c.value;
}).join("; ");

self.headers.Cookie = cookieString;
return c.name + "=" + c.value
}).join("; ")

if (self.headers.cookie) {
// Don't overwrite existing Cookie header
self.headers.cookie += '; ' + cookieString
} else {
self.headers.cookie = cookieString
}
}

if (!self.uri.pathname) {self.uri.pathname = '/'}
Expand Down

0 comments on commit c80800a

Please sign in to comment.