Skip to content

Commit 3b629d2

Browse files
author
Jay Kravetz
committed
Method to send additional cookies in the handshake
1 parent d93ef6a commit 3b629d2

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

lib/server.js

+18-5
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,17 @@ Server.prototype.generateId = function (req) {
281281
return base64id.generateId();
282282
};
283283

284+
/**
285+
* Get additional cookies
286+
* Overwrite this method to have additional serialized cookies sent in the handshake
287+
*
288+
* @param {Object} req object
289+
* @returns {Array}
290+
*/
291+
Server.prototype.getAdditionalCookies = function(req) {
292+
return [];
293+
};
294+
284295
/**
285296
* Handshakes a new client.
286297
*
@@ -317,11 +328,13 @@ Server.prototype.handshake = function (transportName, req) {
317328

318329
if (false !== this.cookie) {
319330
transport.on('headers', function (headers) {
320-
headers['Set-Cookie'] = cookieMod.serialize(self.cookie, id,
321-
{
322-
path: self.cookiePath,
323-
httpOnly: self.cookiePath ? self.cookieHttpOnly : false
324-
});
331+
var cookies = self.getAdditionalCookies(req) || [];
332+
cookies.push(cookieMod.serialize(self.cookie, id, {
333+
path: self.cookiePath,
334+
httpOnly: self.cookiePath ? self.cookieHttpOnly : false
335+
}));
336+
337+
headers['Set-Cookie'] = cookies;
325338
});
326339
}
327340

0 commit comments

Comments
 (0)