To extend the session in the client side, by now I have to set the rolling field to true, but that would cause every request carries the set cookie header.
Could provide a method such as req.session.rollCookie() which allow us roll client side cookie manually?
To clarify: you want the behavior of rolling: true, but you just want to be able to choose which responses will have the set-cookie header instead of every response, is that correct?
@dougwilson yeah, exactly
@zhaoyao91 Setting rolling: true mainly used to refresh set-cookie header(maxAge) for all incoming requests, if the need is to refresh cookie maxAge only for selected requests, I think that can be done manually on requests without setting rolling :true
manually on requests without setting rolling :true
I mean selectively on a per request basis. For example :
if (on some condition) {
req.session.cookie.maxAge = ...
}
I too would like this feature. I want to set the cookie in the response of any html pages I render, but not for static assets (js, css, etc.). The only way to do this now is to reproduce the call to cookie.setcookie() locally, which doesn't seem like a great idea. I also acknowledge that serving static assets from node isn't a best practice, but sometimes simplicity wins.
Hi @Piccirello I think this is a different use-case. For example, with static files, it probably isn't just that you don't want to roll the cookie, but do you even need to go through all the work to load the session at all? If you structure to not invoke the session middleware for static assets, it would not only not roll on those responses, but skip all the work of loading the session in those cases as well.
@dougwilson I was able to implement a better solution based on your info. Thanks for the help!
Most helpful comment
To clarify: you want the behavior of
rolling: true, but you just want to be able to choose which responses will have theset-cookieheader instead of every response, is that correct?