Open ponelat opened 7 years ago
So, this runs a possible callback when the cookies are serialized? And the reason to do this in your case is to so that the 2 cookies are synchronized, and you don't want to forget to update the plaintext cookie accidentally?
Could this also be achieved with another middleware and override res.writeHead
again?
@seanmonstar thanks for the prompt response. Some assumptions:
rawSession
clientSession
will only write the cookie, when rawSession#isDirty
I think decorating writeHead
again isn't a bad idea. But based on the assumptions above, I would need to write my plaintext cookie on every request, as apposed to when clientSession
writes its cookie. Since I don't know when the rawSession
is dirty ( and needs to send a new cookie ).
Hence, I just stuck a callback into client session code. So I could know exactly when clientSession
was going to write its cookie, and I could do something about, it before the headers were sent.
If the session was dirty, you'll see the Set-Cookie
header in res.getHeaders()
, right?
@seanmonstar good point! I'll see if I can't make a workaround with that in mind, thanks!
Hi,
My use case is to synchronize two cookies, one plaintext and the other a secret. This hook allows me to update the plaintext cookie, just as the secret one gets updated.
Would love to get this merged, but don't mind alternatives. If any spring to mind.