Ensure the session is touched before the cookie is set - #296
Conversation
|
I initially struggled quite hard to find out what's happening in the patched _end method and found the separation of commit activities into things that happen 'on header' and in _end a bit arbitrary. Initially, to fix #276, I had the (simple) suggestion to touch the session twice, one 'on headers' and once in '_end' - admittedly not very elegant. So I had another go and unified all session-handling code in 'on headers' and '_end' into one clean method. I believe my PR improves the code for a number of reasons:
All tests pass, including the new one for #276 , however I saw coverage decreased by 0.001%, not sure how to fix this. I am happy to get your comments and suggestions. |
|
Thanks @sboehler! The change is now very big, so it will take quite some time before I can review and accept it now, compared to the first PR, so please bear with me for the length of time it will take. The main reason there was a split is because of course by the time |
|
In addition, and I don't think it's in the tests, your change must support the altering of app.use(function (req, res) {
req.session.foo = 'bar';
res.write('<html>');
setTimeout(function () {
req.session.foo = 'baz';
res.end('</html');
}, 1000);
});Should result in |
|
I also find your code much harder to read, particularly because it's altering |
|
Hi @dougwilson , thanks for the quick feedback.
The easy fix for #276 (which makes the 'rolling' option useless in practice in my use case) could then the initial proposal, touching the session twice (or some way via a global which remembers whether the session has been touched). Could you live with that? My principal ambition is that the behavior of rolling is restored, the other refactoring has been an insightful and fun exercise. Thanks for your work with express, I appreciate it a lot. |
No description provided.