From e08f8e392696009bcf546926c09554dd9019a6c3 Mon Sep 17 00:00:00 2001 From: Asaf Gartner Date: Sun, 27 Jul 2014 19:59:13 +0300 Subject: [PATCH 1/2] Solve issue with redirects When changing the session and then calling `res.redirect(...)` express-session calls `res.write`, which flushes the headers and causes the browser to start redirecting without waiting for the store to finish saving. express-session should not send the headers until the store finishes saving. I patched it for now with a hack. It probably requires a more robust solution. --- index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/index.js b/index.js index 2b886ae0..821203f3 100644 --- a/index.js +++ b/index.js @@ -248,6 +248,8 @@ function session(options){ end.call(res); }); + sync = false; + if (sync) { ret = res.write(chunk, encoding); sync = false; From 096f68e4467169ecb4c3064500921ed817e43bb5 Mon Sep 17 00:00:00 2001 From: Asaf Gartner Date: Mon, 28 Jul 2014 13:17:54 +0300 Subject: [PATCH 2/2] Redirect fix --- index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 821203f3..e5bf7a97 100644 --- a/index.js +++ b/index.js @@ -248,7 +248,9 @@ function session(options){ end.call(res); }); - sync = false; + if (res.statusCode == 301 || res.statusCode == 302) { + sync = false; + } if (sync) { ret = res.write(chunk, encoding);