From 50e3c18d01df6d7201b3e7749f63a2f46406bccc Mon Sep 17 00:00:00 2001 From: Brian J Brennan Date: Mon, 18 Nov 2013 18:04:35 -0500 Subject: [PATCH 1/2] Remove dependency on express/connect Instead of listening for the `header` event, which is something express/connect provides, hijack `writeHead` which gets called implicitly (or explicitly, if the user wants) on every request. --- lib/client-sessions.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/client-sessions.js b/lib/client-sessions.js index 9b419cf..175a579 100644 --- a/lib/client-sessions.js +++ b/lib/client-sessions.js @@ -409,7 +409,7 @@ var cookieSession = function(opts) { if (req[propertyName]) { return next(); //self aware } - + var cookies = new Cookies(req, res); var raw_session; try { @@ -422,9 +422,11 @@ var cookieSession = function(opts) { req[propertyName] = raw_session.monitor(); - res.on('header', function() { + var writeHead = res.writeHead.bind(res) + res.writeHead = function () { raw_session.updateCookie(); - }); + return writeHead.apply(res, arguments) + } next(); }; From 8700d6aee362a41b450ce3f7c65b5c17e6083232 Mon Sep 17 00:00:00 2001 From: Brian J Brennan Date: Mon, 18 Nov 2013 20:03:37 -0500 Subject: [PATCH 2/2] Remove uncessary bind, add semicolons for style. --- lib/client-sessions.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/client-sessions.js b/lib/client-sessions.js index 175a579..2dfbe59 100644 --- a/lib/client-sessions.js +++ b/lib/client-sessions.js @@ -422,10 +422,10 @@ var cookieSession = function(opts) { req[propertyName] = raw_session.monitor(); - var writeHead = res.writeHead.bind(res) + var writeHead = res.writeHead; res.writeHead = function () { raw_session.updateCookie(); - return writeHead.apply(res, arguments) + return writeHead.apply(res, arguments); } next();